本文实例讲述了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. DOM EVENT

    属性 此事件发生在何时... onabort 图像的加载被中断. onblur 元素失去焦点. onchange 域的内容被改变. onclick 当用户点击某个对象时调用的事件句柄. ondblcl ...

  2. uva10167

    /* 暴力 过了 要使得两半的 樱桃数目相等 去试每一个斜率 还好他这里要的是 A.B 都为正整数 这样范围就锁定在200*100 个点范围内 */ #include <cstdio> # ...

  3. 持续集成之三:Maven私服Nexus使用

    环境 Red Hat Enterprise Linux Server release 7.3 (Maipo) jdk1.7.0_80 apache-tomcat-7.0.90 mysql-5.7.23 ...

  4. python之路----常用模块一

    re模块 https://reg.jd.com/reg/person?ReturnUrl=https%3A//www.jd.com/ 这是京东的注册页面,打开页面我们就看到这些要求输入个人信息的提示. ...

  5. mysql8.0无法给用户授权或提示You are not allowed to create a user with GRANT的问题

    提示意思是不能用grant创建用户,mysql8.0以前的版本可以使用grant在授权的时候隐式的创建用户,8.0以后已经不支持,所以必须先创建用户,然后再授权,命令如下: mysql> CRE ...

  6. bzoj1635 / P2879 [USACO07JAN]区间统计Tallest Cow

    P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的 ...

  7. Windows10 蓝屏 DRIVER_IRQL_NOT_LESS_OR_EQUAL (vfilter.sys)的可能解决方法

    早上我的笔记本从休眠中开机的时候突然出现了蓝屏,这个蓝屏在前几天出现过了.两次提示的终止代码都一样.我的笔记本型号是DELL XPS15 9560 我的笔记本配置: 类别 型号 内存 16GB DDR ...

  8. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 1 章 答案

    判断对错1.计算机科学是计算机的研究.2.CPU 是计算机的“大脑”.3.辅助存储器也称为 RAM.4.计算机当前正在处理的所有信息都存储在主存储器中.5.语言的语法是它的意思,语义是它的形式.6.函 ...

  9. 全球变暖|2018年蓝桥杯B组题解析第九题-fishers

    标题:全球变暖 你有一张某海域NxN像素的照片,"."表示海洋."#"表示陆地,如下所示: ....... .##.... .##.... ....##. .. ...

  10. excel的C#操作教程

    C# Excel Tutorial http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm How to transfer ...