本文实例讲述了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实现图形化发牌功能示例的更多相关文章

  1. 如何使用IDEA开发工具中右键中的Git图形化工具

    首先,你的项目一定是git服务器上面down下来的,下面来演示如何使用IntelliJ IDEA 开发中在鼠标右键中提供的一个非常方便的图形化Git管理工具: 这里使用的IDEA开发工具的版本是 In ...

  2. 如何开发自己的搜索帝国之ES图形化Kibana安装与使用

    在如何开发自己的搜索帝国之Elasticsearch中已经介绍安装好了ES,下面就Kibana对ES的查询监控作介绍,就是常提到的大数据日志处理组件ELK里的K. 什么是Kibana?现引用园友的一段 ...

  3. java图形化编程

    转载 学习Java Swing图形化编程,我们首先要了解三个最基本的概念:顶层容器,控件,布局. 下面就来介绍一下这三个基本概念 1.顶层容器 什么是顶层容器?当我们使用Java进行图形编程的时候,图 ...

  4. ROS(indigo) 用于机器人控制的图形化编程工具--code_it robot_blockly

    0 简介: 编程语言有汇编,高级语言,解释语言等,现在图形化编程也越来越流行.图形化编程简单易学.8年前,微软推出了VPL用于机器人程序设计,如Python和JavaScript都可以用图形化框图实现 ...

  5. Native Application 开发详解(直接在程序中调用 ntdll.dll 中的 Native API,有内存小、速度快、安全、API丰富等8大优点)

    文章目录:                   1. 引子: 2. Native Application Demo 展示: 3. Native Application 简介: 4. Native Ap ...

  6. c#调用c++ dll(一)

    首先来说说c++中的dll 核心的一些知识 比较大的应用程序都由很多模块组成,这些模块分别完成相对独立的功能,它们彼此协作来完成整个软件系统的工作.可能存在一些模块的功能较为通用,在构造其它软件系统时 ...

  7. Matlab.NET混合编程调用Figure窗体

    原文:[原创]Matlab.NET混合编程调用Figure窗体 1.前言 做Matlab.NET混合编程好几年了,虽然Matlab很多函数忘记得差不多了,但基本的东西还是能熟练使用.特别是在C#调用M ...

  8. C# 调用外部dll(转)

    C# 调用外部dll   一.      DLL与应用程序 动态链接库(也称为DLL,即为"Dynamic Link Library"的缩写)是Microsoft Windows最 ...

  9. C#调用外部DLL介绍及使用详解

    一.      DLL与应用程序 动态链接库(也称为DLL,即为“Dynamic Link Library”的缩写)是Microsoft Windows最重要的组成要素之一,打开Windows系统文件 ...

随机推荐

  1. Object-C-Foundation-NSDate

    NSDate 表达日期表达时间的方法 NSDate *now=[NSDate date]; 获得当前日期 NSDate *tomrrow=[now dateByAddingTimeInterval:2 ...

  2. Object-C-NSString

    NSString *info=@"Hello world"; NSString *info=[[NSString alloc]initWithFormat:@"my na ...

  3. 如何合并两个Git仓库

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  4. 在windows上构建LLVM 7.0.1

    关于在windows上构建LLVM,网上有不少文章,但都是互相抄来的,写作时极不认真,不是少这个,就是少那个,没有一篇是可以完整照着做下来的,实在气人. 本文的安装和配置过程,我亲自操作过好几遍,不惜 ...

  5. 随意给一组数,找出满足一下条件的a[i],a[i]左边的数小于等于a[i],a[i]右边的数大于等于a[i]

    使用一个额外数组记录每个数后面的最小值是多少,一个额外数组记录一个数前面的最大值是多少,当然,为了减少空间复杂度,可以使用一个数字记录一个数字前面最大值是多少.算法如下: public List< ...

  6. TED #09# You don't have to be an expert to solve big problems

    Tapiwa Chiwewe: You don't have to be an expert to solve big problems Collection noticed a haze hangi ...

  7. 高并发下,php使用uniqid函数生成唯一标识符的四种方案

    PHP uniqid()函数可用于生成不重复的唯一标识符,该函数基于微秒级当前时间戳.在高并发或者间隔时长极短(如循环代码)的情况下,会出现大量重复数据.即使使用了第二个参数,也会重复,最好的方案是结 ...

  8. P1283 平板涂色

    P1283 平板涂色 dfs 记忆化搜索 将矩阵转化为图求解,然后我们发现这是个DAG,于是就可以愉快地跑搜索了. 进行dfs时,我们可以用类似拓扑排序的方法.每次将上面所有矩形都被刷过(入度in[ ...

  9. JavaScript闭包 懂不懂由你反正我是懂了

    原文链接:http://www.jb51.net/article/28611.htm 越来越觉得国内没有教书育人的氛围,为了弄懂JS的闭包,我使出了我英语四级吃奶的劲去google上搜寻着有关闭包的解 ...

  10. 开源项目托管GitHub

    工具:本地HelloWorld源项目 msysgit(Windows) 实验步骤:一.在GitHub新建托管项目 在http://github.com注册账号20159214-sunnan. 完成注册 ...