• C#WinForm4张纸牌窗体设计


    View Code
     public partial class Form2 : Form
        {
            private IList<Card> cards;
    
            private IList<Card> currentCards;
            public Form2 ( )
            {
                InitializeComponent ( );
    
                cards = new List<Card> (52);
                currentCards = new List<Card> (4);
                BuildCardData ( );
            }
    
            private void BuildCardData ( )
            {
                cards.Clear ( );
                for (int i = 1; i <= 13; i++)
                {
                    for (int j = 1; j <= 4; j++)
                    {
                        cards.Add (new Card ((Point) i, (Flower) j));
                    }
                }
            }
    
            private void Form2_Load ( object sender, EventArgs e )
            {
                Reflesh ( );
                RePaint ( );
            }
    
            private void Reflesh ( )
            {
                IList<Card> tmp = new List<Card> (cards);
                
                Random rd = new Random ();
                int intTmp = 0;
                for (int i = 0; i < 4; i++)
                {
                    intTmp = rd.Next (1,52 - i - 1);
                    if (currentCards.Count < i + 1)
                    {
                        currentCards.Add (new Card (Point.A, Flower.Flower));
    
                        #region MyRegion
                        switch (i)
                        {
                            case 0:
                                currentCards[i].gpPalette = Graphics.FromHwnd (pbFirst.Handle);
                                break;
                            case 1:
                                currentCards[i].gpPalette = Graphics.FromHwnd (pbSecond.Handle);
                                break;
                            case 2:
                                currentCards[i].gpPalette = Graphics.FromHwnd (pbThird.Handle);
                                break;
                            case 3:
                                currentCards[i].gpPalette = Graphics.FromHwnd (pbFourth.Handle);
                                break;
                            default:
                                break;
                        }
                        #endregion
                        
                    }
                    currentCards[i].flower=tmp[intTmp].flower;
                    currentCards[i].point = tmp[intTmp].point;
                    tmp.RemoveAt (intTmp);
                }
            }
            private void btnReflesh_Click ( object sender, EventArgs e )
            {
                Reflesh ( );
                RePaint ( );
            }
            private void RePaint ( )
            {
                currentCards[0].Paint ( );
                currentCards[1].Paint ( );
                currentCards[2].Paint ( );
                currentCards[3].Paint ( );
            }
    
            private void pbFirst_Paint ( object sender, PaintEventArgs e )
            {
                currentCards[0].Paint ( e.Graphics);
            }
    
            private void pbSecond_Paint ( object sender, PaintEventArgs e )
            {
                currentCards[1].Paint (e.Graphics);
            }
    
            private void pbThird_Paint ( object sender, PaintEventArgs e )
            {
                currentCards[2].Paint (e.Graphics);
            }
    
            private void pbFourth_Paint ( object sender, PaintEventArgs e )
            {
                currentCards[3].Paint (e.Graphics);
            }
    
        }
  • 相关阅读:
    jquery对同级的td做radio限制
    "javascript:void(0)"用法
    SQL 插入查询的最大ID 号 进行批量
    Java数字、货币值和百分数等的格式化处理
    PHP 注意问题
    Android Fragment真正意义上的onResume和onPause
    Android_CodeWiki_03
    Android_CodeWiki_02
    Android_CodeWiki_01
    Android 启动APP黑屏解决方案
  • 原文地址:https://www.cnblogs.com/guoxiongfei/p/2779174.html
Copyright © 2020-2023  润新知