?? .net學習筆記.txt
字號:
.net學習筆記
http://dev.21tx.com 2006年05月16日
每日文章精萃
.Net:Visual C#編程入門之C#的程序結構 Java:jdbc應用--數據庫連接全集
ASP:ASP 中 DateDiff 函數詳解 PHP:PHP實現自動刷數和“灌水”機
JSP:在JSP開發中模擬.NET WebForm(一) CGI:用Perl語言進行Socket編程之四
VB:一個實現程序啟動窗口界面特效的程序 VC:OICQ登錄號碼清除器實現原理
Form.DialogResult屬性 (表示當窗體用作對話框時該窗體的結果。)
窗體的對話框結果是當窗體顯示為模式對話框時,從該窗體返回的值。如果該窗體顯示為對話框,用來自 DialogResult 枚舉的值設置此屬性可以為該窗體設置對話框結果的值、隱藏該模式對話框并將控件返回到調用窗體。此屬性通常由窗體上 Button 控件的 DialogResult 屬性設置。當用戶單擊 Button 控件時,分配給 Button 的 DialogResult 屬性的值將分配給該窗體的 DialogResult 屬性。
當窗體顯示為模式對話框時,單擊“關閉”按鈕(窗體右上角帶 X 的按鈕)將使窗體隱藏,并使 DialogResult 屬性設置為 DialogResult.Cancel。當用戶單擊對話框的“關閉”按鈕或設置 DialogResult 屬性的該值時,不自動調用 Close 方法。而是隱藏該窗體并可重新顯示該窗體,而不用創建該對話框的新實例。因為此行為,所以當應用程序不再需要該窗體時,必須調用該窗體的 Dispose 方法。
可以使用此屬性確定對話框是如何關閉的,以便正確處理在該對話框中執行的操作。
注意 通過在窗體的 Closing 事件的事件處理程序中設置 DialogResult 屬性,可以重寫用戶單擊“關閉”按鈕時分配給 DialogResult 屬性的值。
注意 如果 Form 顯示為無模式窗口,則 DialogResult 屬性返回的值可能不返回分配給該窗體的值,因為關閉該窗體時將自動釋放該窗體的資源。
[C#]
1public void CreateMyForm()
2 ...{
3 // Create a new instance of the form.
4 Form form1 = new Form();
5 // Create two buttons to use as the accept and cancel buttons.
6 Button button1 = new Button ();
7 Button button2 = new Button ();
8
9 // Set the text of button1 to "OK".
10 button1.Text = "OK";
11 // Set the position of the button on the form.
12 button1.Location = new Point (10, 10);
13 // Set the text of button2 to "Cancel".
14 button2.Text = "Cancel";
15 // Set the position of the button based on the location of button1.
16 button2.Location
17 = new Point (button1.Left, button1.Height + button1.Top + 10);
18 // Make button1's dialog result OK.
19 button1.DialogResult = DialogResult.OK;
20 // Make button2's dialog result Cancel.
21 button2.DialogResult = DialogResult.Cancel;
22 // Set the caption bar text of the form.
23 form1.Text = "My Dialog Box";
24
25 // Define the border style of the form to a dialog box.
26 form1.FormBorderStyle = FormBorderStyle.FixedDialog;
27 // Set the accept button of the form to button1.
28 form1.AcceptButton = button1;
29 // Set the cancel button of the form to button2.
30 form1.CancelButton = button2;
31 // Set the start position of the form to the center of the screen.
32 form1.StartPosition = FormStartPosition.CenterScreen;
33
34 // Add button1 to the form.
35 form1.Controls.Add(button1);
36 // Add button2 to the form.
37 form1.Controls.Add(button2);
38
39 // Display the form as a modal dialog box.
40 form1.ShowDialog();
41
42 // Determine if the OK button was clicked on the dialog box.
43 if (form1.DialogResult == DialogResult.OK)
44 ...{
45 // Display a message box indicating that the OK button was clicked.
46 MessageBox.Show("The OK button on the form was clicked.");
47 // Optional: Call the Dispose method when you are finished with the dialog box.
48 form1.Dispose();
49 }
50 else
51 ...{
52 // Display a message box indicating that the Cancel button was clicked.
53 MessageBox.Show("The Cancel button on the form was clicked.");
54 // Optional: Call the Dispose method when you are finished with the dialog box.
55 form1.Dispose();
56 }
57 }
1[Visual Basic]
2Public Sub CreateMyForm()Sub CreateMyForm()
3 ' Create a new instance of the form.
4 Dim form1 As New Form()
5 ' Create two buttons to use as the accept and cancel buttons.
6 Dim button1 As New Button()
7 Dim button2 As New Button()
8
9 ' Set the text of button1 to "OK".
10 button1.Text = "OK"
11 ' Set the position of the button on the form.
12 button1.Location = New Point(10, 10)
13 ' Set the text of button2 to "Cancel".
14 button2.Text = "Cancel"
15 ' Set the position of the button based on the location of button1.
16 button2.Location = New Point(button1.Left, button1.Height + button1.Top + 10)
17 ' Make button1's dialog result OK.
18 button1.DialogResult = DialogResult.OK
19 ' Make button2's dialog result Cancel.
20 button2.DialogResult = DialogResult.Cancel
21 ' Set the caption bar text of the form.
22 form1.Text = "My Dialog Box"
23
24 ' Define the border style of the form to a dialog box.
25 form1.FormBorderStyle = FormBorderStyle.FixedDialog
26 ' Set the accept button of the form to button1.
27 form1.AcceptButton = button1
28 ' Set the cancel button of the form to button2.
29 form1.CancelButton = button2
30 ' Set the start position of the form to the center of the screen.
31 form1.StartPosition = FormStartPosition.CenterScreen
32
33 ' Add button1 to the form.
34 form1.Controls.Add(button1)
35 ' Add button2 to the form.
36 form1.Controls.Add(button2)
37
38 ' Display the form as a modal dialog box.
39 form1.ShowDialog()
40
41 ' Determine if the OK button was clicked on the dialog box.
42 If form1.DialogResult = DialogResult.OK Then
43 ' Display a message box indicating that the OK button was clicked.
44 MessageBox.Show("The OK button on the form was clicked.")
45 ' Optional: Call the Dispose method when you are finished with the dialog box.
46 form1.Dispose
47 ' Display a message box indicating that the Cancel button was clicked.
48 Else
49 MessageBox.Show("The Cancel button on the form was clicked.")
50 ' Optional: Call the Dispose method when you are finished with the dialog box.
51 form1.Dispose
52 End If
53End Sub 'CreateMyForm
--------------------------------------------------------------------------------
ListView.Activation屬性
Activation 屬性允許您指定用戶激活 ListView 控件中的項的方式。激活 ListView 中的項與只選擇項是不同的。當激活某個項時,通常會在 ItemActivate 事件的事件處理程序中執行一個操作。例如,當激活某個項時,您可能會打開一個文件或顯示一個允許用戶對項進行編輯的對話框。通常,項的激活是通過用戶對它進行雙擊來實現的。如果 Activation 屬性設置為 ItemActivation.OneClick,那么單擊該項一次即可將其激活。將 Activation 屬性設置為 ItemActivation.TwoClick 與標準的雙擊不同,這是因為兩次單擊之間的時間間隔可以是任意的。
注意 如果將 Activation 屬性設置為 ItemActivation.OneClick 或 ItemActivation.TwoClick,則不管 LabelEdit 屬性的值是什么,都不允許進行標簽編輯。
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -