摘要:LinkBetweenChkTxt

"LinkBetweenChkTxt - "#Region "LinkBetweenChkTxt - "
' using the same tag(ID) to form a linkage between the TextBox and CheckBox
' When Checkchange = true, auto Enable TextBox and focus on it 
Public Sub LinkBetweenChkTxt_Master() Sub LinkBetweenChkTxt_Master(ByVal pform As System.Windows.Forms.Form)
Try
Call LinkBetweenChkTxt_SearchChk(pform.Controls)
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Private Sub LinkBetweenChkTxt_SearchChk() Sub LinkBetweenChkTxt_SearchChk(ByVal pControls As System.windows.Forms.Control.ControlCollection)
Try
For Each lcControl As Control In pControls
If lcControl.Controls.Count > 0 Then
LinkBetweenChkTxt_SearchChk(lcControl.Controls)
Else
Select Case lcControl.GetType.Name
Case "CheckBox"
Dim lCheckBox As CheckBox
lCheckBox = lcControl
lCheckBox.Checked = False
AddHandler lCheckBox.CheckedChanged, AddressOf LinkBetweenChkTxt_ChkHandler
End Select
End If
Next
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Private Sub LinkBetweenChkTxt_ChkHandler() Sub LinkBetweenChkTxt_ChkHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
'reviewed
Try
Dim lCheckBox As CheckBox = sender
If lCheckBox.Tag = BLANK Then Exit Sub
If lCheckBox.Checked = True Then
Call LinkBetweenChkTxt_SearchTxt(lCheckBox.Parent.Controls, True, lCheckBox.Tag)
Else
Call LinkBetweenChkTxt_SearchTxt(lCheckBox.Parent.Controls, False, lCheckBox.Tag)
End If
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub 
Private Sub LinkBetweenChkTxt_SearchTxt() Sub LinkBetweenChkTxt_SearchTxt(ByVal pControls As System.windows.Forms.Control.ControlCollection, ByVal pbEnable As Boolean, ByVal psTag As String)
Try
For Each lcControl As Control In pControls
If lcControl.Controls.Count > 0 Then
LinkBetweenChkTxt_SearchTxt(lcControl.Controls, pbEnable, psTag)
Else
Select Case lcControl.GetType.Name
Case "TextBox"
Dim lsTxtbox As TextBox = lcControl
If lsTxtbox.Tag = psTag Then
lsTxtbox.Enabled = pbEnable
If pbEnable = True Then
lsTxtbox.BackColor = Color.White
Else
lsTxtbox.BackColor = System.Drawing.SystemColors.Menu
End If
lsTxtbox.Focus()
If Not pbEnable Then lsTxtbox.Text = BLANK
End If
End Select
End If
Next
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub
#End Region
------------------
熱愛生命 喜愛新奇 有趣的事物
過去 是無法改變
將來 卻能夠創造
希望使大家生活更便利
世界更美好
a guy who loves IT and life