日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

[.NET开发] C#编程调用Cards.dll实现图形化发牌功能示例

發布時間:2025/4/9 C# 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [.NET开发] C#编程调用Cards.dll实现图形化发牌功能示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  本文實例講述了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省事多了

  (編輯:雷林鵬 來源:網絡)

轉載于:https://www.cnblogs.com/pengpeng1208/p/9257740.html

總結

以上是生活随笔為你收集整理的[.NET开发] C#编程调用Cards.dll实现图形化发牌功能示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。