久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C#編程調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能示例

這篇文章主要介紹了C#編程調(diào)用Cards.dll實(shí)現(xiàn)圖形化發(fā)牌功能,結(jié)合實(shí)例形式分析了C#動態(tài)鏈接庫調(diào)用及圖形操作技巧,需要的朋友可以參考下

本文實(shí)例講述了C#編程調(diào)用Cards.dll實(shí)現(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的截尾,相當(dāng)于豎排
         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) //第一種方法實(shí)現(xiàn)隨機(jī)交換牌
     {
      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次隨機(jī)交換兩張牌
       {
        int a = r.Next(52); //生成0--->51的隨機(jī)數(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) //第一種方法實(shí)現(xiàn)隨機(jī)交換牌
     {
      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依次隨機(jī)向前交換獲得最終值
       {
        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);
       }
     }
   }
}

界面設(shè)計(jì)的話截圖比貼Designer.cs省事多了:

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#圖片操作技巧匯總》、《C#常見控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》

希望本文所述對大家C#程序設(shè)計(jì)有所幫助。

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

這篇文章主要為大家詳細(xì)介紹了C# SendMail發(fā)送郵件功能實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
這篇文章主要介紹了C#實(shí)現(xiàn)的SQL備份與還原功能,結(jié)合具體實(shí)例形式分析了C#操作數(shù)據(jù)庫實(shí)現(xiàn)SQL備份與還原相關(guān)的控件、SQL連接、文件等操作技巧,需要的朋友可以參考下
這篇文章主要介紹了C#使用checkedListBox1控件鏈接數(shù)據(jù)庫的方法,結(jié)合具體實(shí)例形式分析了數(shù)據(jù)庫的創(chuàng)建及checkedListBox1控件連接數(shù)據(jù)庫的相關(guān)操作技巧,需要的朋友可以參考下
這篇文章主要介紹了C#實(shí)現(xiàn)的sqlserver操作類,結(jié)合具體實(shí)例形式分析了C#針對sqlserver數(shù)據(jù)庫進(jìn)行連接、查詢、更新、關(guān)閉等相關(guān)操作技巧,需要的朋友可以參考下
這篇文章主要為大家詳細(xì)介紹了HttpHelper類的使用方法,HttpHelper類及調(diào)用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
這篇文章主要為大家詳細(xì)介紹了C#多線程數(shù)組模擬socket的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
主站蜘蛛池模板: 精品国产伦一区二区三区观看方式 | 91久久久久 | 欧美激情精品久久久久久变态 | 亚洲综合三区 | 免费一级做a爰片久久毛片潮喷 | 午夜男人视频 | 国产一区二区三区 | 久久久久久久网 | 91精品久久久 | 国产精品久久亚洲 | 国产精品一区二区三区久久 | 国产九九九九 | 久久久91精品国产一区二区三区 | 精品国产一区二区三区久久久蜜月 | 日韩精品免费在线观看 | 成人免费视频7777777 | 午夜精品一区二区三区在线视频 | 国产精品揄拍一区二区 | 欧美va大片| 久久伊 | www.av在线| 久久不射电影网 | 中文字幕亚洲欧美 | www.亚洲成人网 | 国产精品99视频 | 亚洲午夜精品一区二区三区他趣 | 91av免费版| 欧美成人一区二区三区片免费 | 福利国产| 久久精品视频网站 | 一区中文字幕 | 国外成人在线视频 | 日韩在线免费视频 | 色香婷婷| 91久久精品 | 亚洲精品视频一区 | 成人一区二区视频 | 亚洲小视频在线观看 | 美女黄视频网站 | 亚洲精品电影在线观看 | 九九av|