亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2017年06月26日 11:29:33   作者:songkexin  
這篇文章主要介紹了C#編程調(diào)用Cards.dll實現(xiàn)圖形化發(fā)牌功能,結(jié)合實例形式分析了C#動態(tài)鏈接庫調(diào)用及圖形操作技巧,需要的朋友可以參考下

本文實例講述了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);
       }
     }
   }
}

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

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

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

相關(guān)文章

  • Response.Redirect 正在中止線程解決方案

    Response.Redirect 正在中止線程解決方案

    這兩天在開發(fā)調(diào)試過程中,老是會出現(xiàn)在一個 "正在中止線程“(ThreadAbortException)的例外信息,很是疑惑,于是網(wǎng)上收集整理了一下,現(xiàn)在曬出來和大家分享,希望對你們有幫助
    2012-11-11
  • Unity代碼實現(xiàn)序列幀動畫播放器

    Unity代碼實現(xiàn)序列幀動畫播放器

    這篇文章主要為大家詳細介紹了Unity代碼實現(xiàn)序列幀動畫播放器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • asp.net core 使用 tensorflowjs實現(xiàn) face recognition的源代碼

    asp.net core 使用 tensorflowjs實現(xiàn) face recognition的源代碼

    tensorflowjs,在該項目中使用了ml5js這個封裝過的機器學習JavaScript類庫, 使用起來更簡單,本文給大家分享asp.net core 使用 tensorflowjs實現(xiàn) face recognition的源代碼,需要的朋友參考下吧
    2021-06-06
  • c#文本加密程序代碼示例

    c#文本加密程序代碼示例

    這是一個加密軟件,但只限于文本加密,加了窗口控件的滑動效果,詳細看下面的代碼
    2013-11-11
  • C#判斷單詞個數(shù)方法總結(jié)

    C#判斷單詞個數(shù)方法總結(jié)

    我們給大家總計了C#中判斷英文單詞個數(shù)的方法以及排序的技巧,對此有需要的朋友可以測試下。
    2018-03-03
  • C#中子類調(diào)用父類的實現(xiàn)方法

    C#中子類調(diào)用父類的實現(xiàn)方法

    這篇文章主要介紹了C#中子類調(diào)用父類的實現(xiàn)方法,通過實例逐步分析了類中初始化構(gòu)造函數(shù)的執(zhí)行順序問題,有助于加深對C#面向?qū)ο蟪绦蛟O(shè)計的理解,需要的朋友可以參考下
    2014-09-09
  • C#各類集合匯總

    C#各類集合匯總

    這篇文章主要介紹了C#各類集合的相關(guān)資料,文中示例代碼非常詳細,幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-07-07
  • Unity Shader實現(xiàn)翻書效果

    Unity Shader實現(xiàn)翻書效果

    這篇文章主要為大家詳細介紹了Unity Shader實現(xiàn)翻書效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • C#編寫的生辰八字計算程序

    C#編寫的生辰八字計算程序

    這篇文章主要介紹了C#編寫的生辰八字計算程序,假設(shè)一個人的公歷出生時間,范圍必須要在2012-2015年之間,因為本示例程序只提供了這幾年的農(nóng)歷數(shù)據(jù),小伙伴們參考下,可以自由擴展
    2015-03-03
  • c# 基于wpf,開發(fā)OFD電子文檔閱讀器

    c# 基于wpf,開發(fā)OFD電子文檔閱讀器

    這篇文章主要介紹了c# 如何基于wpf,開發(fā)OFD電子文檔閱讀器,幫助大家更好的理解和學習使用c#的wpf技術(shù),感興趣的朋友可以了解下
    2021-03-03

最新評論