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}