本文实例讲述了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省事多了:
更多关于C#相关内容感兴趣的读者可查看本站专题:《C#图片操作技巧汇总》、《C#常见控件用法教程》、《WinForm控件用法总结》、《C#数据结构与算法教程》、《C#面向对象程序设计入门教程》及《C#程序设计之线程使用技巧总结》
希望本文所述对大家C#程序设计有所帮助。
# C#
# 调用
# Cards.dll
# 图形化
# 发牌
# C#代码实现扑克牌排序的几种方式
# C#实现洗牌游戏实例
# C# L型棋牌覆盖实现代码与效果
# C#编写控制台程序纸牌游戏
# 程序设计
# 种方法
# 随机数
# 相关内容
# 感兴趣
# 数据结构
# 给大家
# 更多关于
# 试了
# 所述
# 使用技巧
# 面向对象
# 编了
# 操作技巧
# 讲述了
# 两张牌
# ref
# cdtInit
# bool
相关文章:
企业微网站怎么做,公司网站和公众号有什么区别?
香港网站服务器数量如何影响SEO优化效果?
建站10G流量真的够用吗?如何应对访问高峰?
如何确保西部建站助手FTP传输的安全性?
如何在香港服务器上快速搭建免备案网站?
建站之星logo尺寸如何设置最合适?
建站之星后台密码遗忘?如何快速找回?
电商平台网站制作流程,电商网站如何制作?
小视频制作网站有哪些,有什么看国内小视频的网站,求推荐?
大连 网站制作,大连天途有线官网?
建站主机默认首页配置指南:核心功能与访问路径优化
网站设计制作企业有哪些,抖音官网主页怎么设置?
制作无缝贴图网站有哪些,3dmax无缝贴图怎么调?
番禺网站制作公司哪家值得合作,番禺图书馆新馆开放了吗?
教学论文网站制作软件有哪些,写论文用什么软件
?
在线ppt制作网站有哪些,请推荐几个好的课件下载的网站?
建站之星展会模版如何一键下载生成?
如何通过虚拟主机快速搭建个人网站?
公司网站制作需要多少钱,找人做公司网站需要多少钱?
如何快速搭建响应式可视化网站?
宠物网站制作html代码,有没有专门介绍宠物如何养的网站啊?
历史网站制作软件,华为如何找回被删除的网站?
东莞专业网站制作公司有哪些,东莞招聘网站哪个好?
linux top下的 minerd 木马清除方法
如何在云指建站中生成FTP站点?
网站制作多少钱一个,建一个论坛网站大约需要多少钱?
如何用西部建站助手快速创建专业网站?
建站之星如何实现PC+手机+微信网站五合一建站?
如何在Ubuntu系统下快速搭建WordPress个人网站?
道歉网站制作流程,世纪佳缘致歉小吴事件,相亲网站身份信息伪造该如何稽查?
网站制作壁纸教程视频,电脑壁纸网站?
Swift中循环语句中的转移语句 break 和 continue
如何选择适配移动端的WAP自助建站平台?
常州自助建站工具推荐:低成本搭建与模板选择技巧
网站插件制作软件免费下载,网页视频怎么下到本地插件?
常州企业建站如何选择最佳模板?
Python如何创建带属性的XML节点
公司网站建设制作费用,想建设一个属于自己的企业网站,该如何去做?
制作网站怎么制作,*游戏网站怎么搭建?
制作企业网站建设方案,怎样建设一个公司网站?
建站之星如何实现网站加密操作?
h5网站制作工具有哪些,h5页面制作工具有哪些?
如何在IIS服务器上快速部署高效网站?
建站之星收费标准详解:套餐费用及年费价格表一览
如何在建站之星绑定自定义域名?
建站之星各版本价格是多少?
建站之星备案流程有哪些注意事项?
建站之星备案是否影响网站上线时间?
c# 在高并发场景下,委托和接口调用的性能对比
建站之星×万网:智能建站系统+自助建站平台一键生成
*请认真填写需求信息,我们会在24小时内与您取得联系。