[.NET开发] C#编程调用Cards.dll实现图形化发牌功能示例
本文实例讲述了C#编程调用Cards.dll实现图形化发牌功能。分享给大家供大家参考,具体如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Windows.Forms.Design;
namespace GetCards
{
public partial class Form1 : Form
{
[DllImport("cards.dll")]
public static extern bool cdtInit(ref int width, ref int height);
[DllImport("cards.dll")]
public static extern void cdtTerm();
[DllImport("cards.dll")]
public static extern bool cdtDraw(IntPtr hdc,int x,int y,int card,int mode,long color);
//mode=0表正面,1表反面,Color我从0-0xFF000试了很多,好象没颜色改变
//[DllImport("cards.dll")]
//public static extern bool cdtDrawExt(IntPtr hdc,int x,int y,int dx,int dy,int card,int type,long color);
//[DllImport("cards.dll")]
//public static extern bool cdtAnimate(IntPtr hdc,int cardback,int x,int y,int frame);
int[] bb = new int[100];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int width, height;
width = 0; height = 0;
cdtInit(ref width, ref height);
}
private void btn_PaintCard_Click(object sender, EventArgs e)
{
int i, k, left_x, top_y, CardId;
for (k = 0; k <= 3; k++)
{
for (i = 1; i <= 13; i++)
{
left_x = 20 + (i - 1) * 15; //牌的重叠后的宽度是15
top_y = 20 + k * 100; //每行13张牌.高度是20
CardId = (i - 1) * 4 + k; //原来52张牌是编了号的
cdtDraw(this.CreateGraphics().GetHdc(), left_x, top_y, CardId, 0,9);
}
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
cdtTerm();
}
private void btn_PaintBack_Click(object sender, EventArgs e)
{
int i, left_x, top_y, BackId;
for (i = 0; i <= 11; i++) //12张牌背面图
{
BackId = i;
top_y = 20 + (i & 3) * 100; //小于等于3的不变,>3的截尾,相当于竖排
left_x = 20 + (i >> 2) * 80 + 180 + 80; //左边牌占15*12+80=260,也就是和最右张牌20(隐含了牌大小=80)
cdtDraw(this.CreateGraphics().GetHdc(), left_x, top_y, 54 + BackId, 1, 9);
}
}
private void btn_Random1_Click(object sender, EventArgs e) //第一种方法实现随机交换牌
{
int ii, k, left_x, top_y, CardId;
int[] theArray = new int[52];
Random r = new Random();
listBox1.Items.Clear();
for (int i = 0; i < 52; i++)
{
theArray[i] = i + 1;
}
for (int i = 0; i < 52; i++) //就是做52次随机交换两张牌
{
int a = r.Next(52); //生成0--->51的随机数
int b = r.Next(52);
int tmp = theArray[a];
theArray[a] = theArray[b];
theArray[b] = tmp;
}
for (int i = 0; i < 52; i++)
{
listBox1.Items.Add(theArray[i]);
k = (int)(i / 13);
ii = i % 13 + 1;
left_x = 20 + (ii - 1) * 15;
top_y = 20 + k * 100;
CardId = theArray[i] - 1;
cdtDraw(this.CreateGraphics().GetHdc(), left_x, top_y, CardId, 0, 9);
}
}
private void btn_Random2_Click(object sender, EventArgs e) //第一种方法实现随机交换牌
{
int ii, k, left_x, top_y, CardId;
int[] theArray = new int[52];
int i = 0;
while (i < theArray.Length)
{
theArray[i] = ++i;
}
Random r = new Random();
listBox1.Items.Clear();
while (i > 1) //从51-->1依次随机向前交换获得最终值
{
int j = r.Next(i);
int t = theArray[--i];
theArray[i] = theArray[j];
theArray[j] = t;
}
for (i = 0; i < theArray.Length; ++i)
{
listBox1.Items.Add(theArray[i].ToString());
k = (int)(i / 13);
ii = i % 13 + 1;
left_x = 20 + (ii - 1) * 15;
top_y = 20 + k * 100;
CardId = theArray[i] - 1;
cdtDraw(this.CreateGraphics().GetHdc(), left_x, top_y, CardId, 0, 9);
}
}
}
}
复制代码
界面设计的话截图比贴Designer.cs省事多了
(编辑:雷林鹏 来源:网络)
[.NET开发] C#编程调用Cards.dll实现图形化发牌功能示例的更多相关文章
- 如何使用IDEA开发工具中右键中的Git图形化工具
首先,你的项目一定是git服务器上面down下来的,下面来演示如何使用IntelliJ IDEA 开发中在鼠标右键中提供的一个非常方便的图形化Git管理工具: 这里使用的IDEA开发工具的版本是 In ...
- 如何开发自己的搜索帝国之ES图形化Kibana安装与使用
在如何开发自己的搜索帝国之Elasticsearch中已经介绍安装好了ES,下面就Kibana对ES的查询监控作介绍,就是常提到的大数据日志处理组件ELK里的K. 什么是Kibana?现引用园友的一段 ...
- java图形化编程
转载 学习Java Swing图形化编程,我们首先要了解三个最基本的概念:顶层容器,控件,布局. 下面就来介绍一下这三个基本概念 1.顶层容器 什么是顶层容器?当我们使用Java进行图形编程的时候,图 ...
- ROS(indigo) 用于机器人控制的图形化编程工具--code_it robot_blockly
0 简介: 编程语言有汇编,高级语言,解释语言等,现在图形化编程也越来越流行.图形化编程简单易学.8年前,微软推出了VPL用于机器人程序设计,如Python和JavaScript都可以用图形化框图实现 ...
- Native Application 开发详解(直接在程序中调用 ntdll.dll 中的 Native API,有内存小、速度快、安全、API丰富等8大优点)
文章目录: 1. 引子: 2. Native Application Demo 展示: 3. Native Application 简介: 4. Native Ap ...
- c#调用c++ dll(一)
首先来说说c++中的dll 核心的一些知识 比较大的应用程序都由很多模块组成,这些模块分别完成相对独立的功能,它们彼此协作来完成整个软件系统的工作.可能存在一些模块的功能较为通用,在构造其它软件系统时 ...
- Matlab.NET混合编程调用Figure窗体
原文:[原创]Matlab.NET混合编程调用Figure窗体 1.前言 做Matlab.NET混合编程好几年了,虽然Matlab很多函数忘记得差不多了,但基本的东西还是能熟练使用.特别是在C#调用M ...
- C# 调用外部dll(转)
C# 调用外部dll 一. DLL与应用程序 动态链接库(也称为DLL,即为"Dynamic Link Library"的缩写)是Microsoft Windows最 ...
- C#调用外部DLL介绍及使用详解
一. DLL与应用程序 动态链接库(也称为DLL,即为“Dynamic Link Library”的缩写)是Microsoft Windows最重要的组成要素之一,打开Windows系统文件 ...
随机推荐
- zw版【转发·台湾nvp系列Delphi例程】HALCON SigmaImage1
zw版[转发·台湾nvp系列Delphi例程]HALCON SigmaImage1 procedure TForm1.Button1Click(Sender: TObject);var img, im ...
- mysql系统变量查询
mysql系统变量包括全局变量(global)和会话变量(session),global变量对所有session生效,session变量包括global变量.mysql调优必然会涉及这些系统变量的调整 ...
- python xml练习:从database.xml文件取databaselist的ip、name、passwd,写入列表
xml: <?xml version='1.1' encoding='utf-8'?><!--this is a test about xml--><databaseli ...
- excel选择元角分下拉菜单选择框自动变更数字
excel选择元角分下拉菜单选择框自动变更数字 (M2列),数据-->数据有效性-->在“允许”栏中选择序列-->在“来源”栏中输入:分,角,元单位倍数公式(M4列):=IF(M2= ...
- git必备命令
git status 查看git的状态git add <path>的形式把我们<path>添加到索引库中,<path>可以是文件也可以是目录.git add -u ...
- NetSuite助力各行业企业快速发展
Oracle NetSuite今天发布了一系列全新技术创新,帮助各行各业企业提升收入.海外扩张以及赋能更多业务用户.最新推出的商务管理.财务管理和分析能力可协助企业利用NetSuite平台来超越客户预 ...
- (一)MySQL登录与退出
mysql登陆: win+r输入cmd按enter进入命令行界面: > mysql -uroot -p -P3306 -h127.0.0.1 > 输入密码后按回车 mysql退出: mys ...
- Android Socket 知识点汇总
版权声明:这篇博客资料来源 https://blog.csdn.net/carson_ho/article/details/53366856 , 未经授权,严禁转发! 一.网络基础 1.1 计算机网络 ...
- UVa 1451 Average - 斜率优化
A DNA sequence consists of four letters, A, C, G, and T. The GC-ratio of a DNA sequence is the numbe ...
- 不是最强大的vimrc
一直都是使用vim作为我的主要编辑器,它大大提高了我的代码编辑效率.vim的配置高度灵活.插件丰富,恐怕100个人就有99种配置方法,网上关于vim配置的所谓“最强大的vimrc”之类的文章不少,博人 ...