zoukankan      html  css  js  c++  java
  • 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);
            }
    
        }
  • 相关阅读:
    1061 Dating (20 分)
    1112 Stucked Keyboard (20 分)
    1077 Kuchiguse (20 分)
    1065 A+B and C (64bit) (20 分)
    1046 Shortest Distance (20 分)
    1124 Raffle for Weibo Followers (20 分)
    1036 Boys vs Girls (25 分)
    1113 Integer Set Partition (25 分)
    f开头的
    g开头的
  • 原文地址:https://www.cnblogs.com/guoxiongfei/p/2779174.html
Copyright © 2011-2022 走看看