WinForm form application (preliminary) 2. winform form

Source: Internet
Author: User

WinForm form application (preliminary) 2. winform form

Now let's take a look at some basic controls. Controls are placed in the toolbox. You can find them on the left side of the interface or through the view options in the menu bar.

(1) Label control: This is a control used to place text, because you cannot directly enter text on the form.

(2) TextBox

(3) Button

(4) CheckBox check box

(5) Panel grouping container, similar to div in HTML

(6) PictureBox image box

(7) WebBrowser: allows users to browse webpages in the form and can be used to create browsers.

The following is a self-developed jigsaw puzzle game and code file:

1 using System; 2 using System. collections; 3 using System. collections. generic; 4 using System. componentModel; 5 using System. data; 6 using System. drawing; 7 using System. linq; 8 using System. text; 9 using System. threading. tasks; 10 using System. windows. forms; 11 12 namespace WindowsFormsApplication1 13 {14 public partial class Form1: Form 15 {16 public Form1 () 17 {18 InitializeComponent (); 19 ImgList = null; 20} 21 # region defined field 22 List <Image> _ imgList; 23 // <summary> 24 // define attribute 25 /// </summary> 26 public List <Image> ImgList 27 {28 get {return _ imgList ;} 29 set 30 {31 _ imgList = new List <Image> (); 32 _ imgList. add (pictureBox1.BackgroundImage); 33 _ imgList. add (pictureBox2.BackgroundImage); 34 _ imgList. add (pictureBox3.BackgroundImage); 35 _ imgList. add (pictureBox4.BackgroundImage ); 36 _ imgList. add (pictureBox5.BackgroundImage); 37 _ imgList. add (pictureBox6.BackgroundImage); 38} 39} 40 # endregion 41 # region start button 42 private void button#click (object sender, EventArgs e) 43 {44 // Random 6 different numbers 45 Random rd = new Random (); 46 int [] x = new int [6]; 47 for (int I = 0; I <6; I ++) 48 {49 x [I] = rd. next (0, 6); 50 for (int j = 0; j <I; j ++) 51 {52 if (x [I] = x [j]) 53 {54 I --; 55 br Eak; 56} 57} 58} 59 // reset image 60 pictureBox1.BackgroundImage = ImgList [x [0]; 61 pictureBox2.BackgroundImage = ImgList [x [1]; 62 pictureBox3.BackgroundImage = ImgList [x [2]; 63 pictureBox4.BackgroundImage = ImgList [x [3]; 64 pictureBox5.BackgroundImage = ImgList [x [4]; 65 pictureBox6.BackgroundImage = ImgList [x [5]; 66 // start of countdown and allow player operation 67 time = 5; 68 label2.Text = "5"; 69 timer1.Start (); 70 pictur EBox1.Enabled = true; 71 pictureBox2.Enabled = true; 72 pictureBox3.Enabled = true; 73 pictureBox4.Enabled = true; 74 pictureBox5.Enabled = true; 75 pictureBox6.Enabled = true; 76} 77 # endregion 78 # region player operation 79 // define the matching variable 80 int match = 0; 81 // Save the image 82 PictureBox lpb = new PictureBox (); 83 // response to user operation 84 private void picturebox#click (object sender, EventArgs e) 85 {86 PictureBox pb = sender PictureBox; 87 // capture the last digit of the Name as the unique identifier 88 int n = int. parse (pb. name. substring (10, 1); 89 // determines whether the bitwise is correct. if the bitwise is not correct, 90 if (pb. backgroundImage! = ImgList [n-1]) 91 {92 // reset the parameter 93 if (match = 2) 94 {95 match = 0; 96} 97 // exchange the background Image 98 if (match = 1) 99 {100 Image img = pb. backgroundImage; 101 pb. backgroundImage = lpb. backgroundImage; 102 lpb. backgroundImage = img; 103 // determine whether all data is returned. 104 if (pictureBox1.BackgroundImage = ImgList [0] & amp; # = ImgList [1] & amp; # = ImgList [2] Mage = ImgList [3] & pictureBox5.BackgroundImage = ImgList [4] & pictureBox6.BackgroundImage = ImgList [5]) 105 {106 timer1.Stop (); 107 MessageBox. show ("Congratulations! "); 108} 109} 110 lpb = pb; 111 match ++; 112} 113} 114 # endregion115 # region timing function 116 int time = 5; 117 private void timereffectick (object sender, EventArgs e) 118 {119 if (time> 0) 120 {121 time --; 122 label2.Text = time. toString (); 123} 124 else125 {126 // stop timing and disable player operations 127 timer1.Stop (); 128 pictureBox1.Enabled = false; 129 pictureBox2.Enabled = false; 130 pictureBox3.Enabled = false; 131 pictureBox4.Enabled = fa Lse; 132 pictureBox5.Enabled = false; 133 pictureBox6.Enabled = false; 134 MessageBox. Show ("sorry, the game failed! "); 135} 136} 137 # endregion138 139 140 141} 142}View Code

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.