WinForms control programming skills

Source: Internet
Author: User

1. Enter the dialog box:

Original article: http://blog.csdn.net/yanleigis/archive/2007/10/10/1818268.aspx

Code
1 private string InputBox (string Caption, string Hint, string Default)
2 {
3 // by Lei Email: Landgis@126.com, yanleigis@21cn.com 2007.10.10
4 Form InputForm = new Form ();
5 InputForm. MinimizeBox = false;
6 InputForm. MaximizeBox = false;
7 InputForm. StartPosition = FormStartPosition. CenterScreen;
8 InputForm. Width = 220;
9 InputForm. Height = 150;
10 // InputForm. Font. Name = "";
11 // InputForm. Font. Size = 10;
12
13 InputForm. Text = Caption;
14 Label lbl = new Label ();
15 lbl. Text = Hint;
16 lbl. Left = 10;
17 lbl. Top = 20;
18 lbl. Parent = InputForm;
19 lbl. AutoSize = true;
20 TextBox tb = new TextBox ();
21 tb. Left = 30;
22 tb. Top = 45;
23 tb. Width = 160;
24 tb. Parent = InputForm;
25 tb. Text = Default;
26 tb. SelectAll ();
27 Button btnok = new Button ();
28 btnok. Left = 30;
29 btnok. Top = 80;
30 btnok. Parent = InputForm;
31 btnok. Text = "OK ";
32 InputForm. AcceptButton = btnok; // return the response
33
34 btnok. DialogResult = DialogResult. OK;
35 Button btncancal = new Button ();
36 btncancal. Left = 120;
37 btncancal. Top = 80;
38 btncancal. Parent = InputForm;
39 btncancal. Text = "cancel ";
40 btncancal. DialogResult = DialogResult. Cancel;
41 try
42 {
43 if (InputForm. ShowDialog () = DialogResult. OK)
44 {
45 return tb. Text;
46}
47 else
48 {
49 return null;
50}
51}
52 finally
53 {
54 InputForm. Dispose ();
55}
56
57}

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.