重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
小编给大家分享一下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#中如何调用Cards.dll实现图形化发牌功能”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联网站建设公司行业资讯频道!
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。