本文实例讲述了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. 改变 select下拉框 样式

    select{ outline: none; text-indent: 10px; height: 45px; line-height: 45px; width: 100%; border:1px s ...

  2. 深入理解 Java 内存模型(一)- 内存模型介绍

    深入理解 Java 内存模型(一)- 内存模型介绍 深入理解 Java 内存模型(二)- happens-before 规则 深入理解 Java 内存模型(三)- volatile 语义 深入理解 J ...

  3. linux脚本-判断进程是否存在,从而可以做预警处理..

    count=`ps -ef | grep Seeyon | grep -v "grep" | wc -l` echo $count if [ $count -gt 0 ]; the ...

  4. OS X 下动态库的引用

    foo.c #include <stdio.h> void foo(void) { printf("foo.\n"); } main.c #include <st ...

  5. Python: 字典列表: itemgetter 函数: 根据某个或某几个字典字段来排序列表

    问题:根据某个或某几个字典字段来排序Python列表 answer: 通过使用operator 模块的itemgetter 函数,可以非常容易的排序这样的数据结构 eg: rows = [ {'fna ...

  6. json-lib基础

    一.json-lib所需的jar包: json-lib.jar,commons-beanutils.jar,commons-collections.jar,commons-lang.jar,commo ...

  7. php array_multisort对数据库结果多个字段进行排序

    php array_multisort对数据库结果多个字段进行排序$data 数组中的每个单元表示一个表中的一行.这是典型的数据库记录的数据集合. 例子中的数据如下:volume | edition ...

  8. Spring IOC 源码分析

    Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不好好了解 Spring 呢?阅读本文 ...

  9. 05: 配置yum源

    1.1 将镜像复制到本地创建yum源 1.将准备好的系统镜像放到指定的目录,本次目录指定在:/dawnfs/sourcecode 2.创建挂载目录:mkdir /mnt/yum 3.挂载镜像: mou ...

  10. Python3基础 try-except-finally 的简单示例

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...