本文实例讲述了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. 模仿WIN32程序处理消息

    #include "stdafx.h" #include "MyMessage.h" #include <conio.h> using namesp ...

  2. 何为仿射变换(Affine Transformation)

    http://www.cnblogs.com/ghj1976/p/5199086.html 变换模型是指根据待匹配图像与背景图像之间几何畸变的情况,所选择的能最佳拟合两幅图像之间变化的几何变换模型.可 ...

  3. html文件上传控件file自定义样式

    问题: HTML自带的file上传按钮因在各种浏览器里显示样式不一.不易自定义样式给我们带来很大的麻烦. 解决思路: 将input[type=file]控件隐藏,使用一个input[type=text ...

  4. Python Web学习笔记之进程与线程

    要了解二者的区别与联系,首先得对进程与线程有一个宏观上的了解. 进程,是并发执行的程序在执行过程中分配和管理资源的基本单位,是一个动态概念,竟争计算机系统资源的基本单位.每一个进程都有一个自己的地址空 ...

  5. 通过一个例子了解Ajax

    Ajax指的Asyncronous JavaScript and XML Ajax并不是什么新的编程语言, 它是现有一些东西的应用.从它的名称中就可以看出来 假如我们设想, 浏览器展示了一个页面,但需 ...

  6. Rubin-Miller与Pollard Rho

    两个没什么卵用的算法. 只放一下模板: BZOJ3667 //BZOJ 3667 //by Cydiater //2017.2.20 #include <iostream> #includ ...

  7. windows下的 gvim - su'blime text 的使用

    su'blime [s2'blaim] adj. n. 崇高的, 高尚的, 令人尊敬的; 壮丽的, 宏伟的; 出众的; 崇高的人, 壮丽的事物等等. a sublime mission. a subl ...

  8. FJNUOJ the greed of Yehan(最长路 + 权值乘积转化)题解

    Description During the trip, Yehan and Linlin pass a cave, and there is a board at the door, which s ...

  9. 自定义redis序列化工具

    redis一个优点就是可以将数据写入到磁盘中. 我们知道写入磁盘的数据实际上都是以字节(0101这样的二进制数据)的形式写入的. 这意味着如果我们要将一个对象写入磁盘,就必须将这个对象序列化. jav ...

  10. zedgraph多个graphpane的处理

    这个问题需要研究,需要使用  zedgraph.masterpane.panelist 其他人做的效果--先预留一个官网的链接http://zedgraph.dariowiz.com/index113 ...