C#編程調(diào)用Cards.dll實現(xiàn)圖形化發(fā)牌功能示例
本文實例講述了C#編程調(diào)用Cards.dll實現(xiàn)圖形化發(fā)牌功能。分享給大家供大家參考,具體如下:
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) //第一種方法實現(xiàn)隨機交換牌 { 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的隨機數(shù) 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) //第一種方法實現(xiàn)隨機交換牌 { 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#相關內(nèi)容感興趣的讀者可查看本站專題:《C#圖片操作技巧匯總》、《C#常見控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#面向?qū)ο蟪绦蛟O計入門教程》及《C#程序設計之線程使用技巧總結(jié)》
希望本文所述對大家C#程序設計有所幫助。
上一篇:C# SendMail發(fā)送郵件功能實現(xiàn)
欄 目:C#教程
本文標題:C#編程調(diào)用Cards.dll實現(xiàn)圖形化發(fā)牌功能示例
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5630.html
您可能感興趣的文章
- 01-10C#編程實現(xiàn)自定義熱鍵的方法
- 01-10C#調(diào)用dos窗口獲取相關信息的方法
- 01-10C#編程獲取資源文件中圖片的方法
- 01-10同步調(diào)用和異步調(diào)用WebService
- 01-10C#調(diào)用WebService實例開發(fā)
- 01-10C#編程自學之數(shù)據(jù)類型和變量二
- 01-10C#編程自學之開篇介紹
- 01-10C#編程自學之數(shù)據(jù)類型和變量三
- 01-10C#編程自學之運算符和表達式
- 01-10C#編程自學之類和對象


閱讀排行
本欄相關
- 01-10C#通過反射獲取當前工程中所有窗體并
- 01-10關于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實現(xiàn)txt定位指定行完整實例
- 01-10WinForm實現(xiàn)仿視頻 器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實現(xiàn)讀取注冊表監(jiān)控當前操作系統(tǒng)已
隨機閱讀
- 01-10C#中split用法實例總結(jié)
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 04-02jquery與jsp,用jquery
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文