1. 在WinForm 中添加控件TextBox(TextBox1), Button(Button1),Button(Button2). 并添加如下代码. 如果TextBox1是Focused. 无论click Button1或Button2, Private Sub TextBox1_Validating 的代码执行. 问题: 如果click Button1, 我不执行Private Sub TextBox1_Validating 的代码; 如果click Button2, Private Sub TextBox1_Validating 的代码照常执行; 请将下面代码改进.
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If Not IsValidated() Then
e.Cancel = True
End If
End Sub
Private Function IsValidated() As Boolean
'Do Validating
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
2. 第二问题是如何Disable WinForm 右上角的按钮"X". 不用Windows API, 纯.NET
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If Not IsValidated() Then
e.Cancel = True
End If
End Sub
Private Function IsValidated() As Boolean
'Do Validating
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
2. 第二问题是如何Disable WinForm 右上角的按钮"X". 不用Windows API, 纯.NET