Public is_Dirty As Boolean =
FalsePublic lstHandlersToCleanUp As New List(Of Object)
Function funEstablishGetDirty(ctrlProcess As Control)
For Each c As Control In ctrlProcess.Controls
Debug.Print(">" & c.Name)
If TypeOf c Is ComboBox Then
Dim tb As ComboBox = CType(c, ComboBox)
AddHandler tb.TextChanged, AddressOf SetIsDirty
lstHandlersToCleanUp.Add(tb)
Debug.Print("Adding: " & tb.Name)
ElseIf TypeOf c Is GroupBox Then
funEstablishGetDirty(c)
ElseIf TypeOf c Is Panel Then
funEstablishGetDirty(c)
ElseIf TypeOf c Is tabcontrol Then
funEstablishGetDirty(c)
ElseIf TypeOf c Is checkbox Then
Dim tb As CheckBox = CType(c, CheckBox)
AddHandler tb.CheckedChanged, AddressOf SetIsDirty
lstHandlersToCleanUp.Add(tb)
Debug.Print("Adding: " & tb.Name)
ElseIf TypeOf c Is DateTimePicker Then
Dim tb As DateTimePicker = CType(c, DateTimePicker)
AddHandler tb.ValueChanged, AddressOf SetIsDirty
lstHandlersToCleanUp.Add(tb)
Debug.Print("Adding: " & tb.Name)
ElseIf TypeOf c Is TextBox Then
Dim tb As TextBox = CType(c, TextBox)
AddHandler tb.TextChanged, AddressOf SetIsDirty
lstHandlersToCleanUp.Add(tb)
Debug.Print("Adding: " & tb.Name)
ElseIf TypeOf c Is RadioButton Then
Dim tb As RadioButton = CType(c, RadioButton)
AddHandler tb.CheckedChanged, AddressOf SetIsDirty
lstHandlersToCleanUp.Add(tb)
Debug.Print("Adding: " & tb.Name)
End If
'If TypeOf c Is ComboBoxEdit Then
' Dim cb As ComboBoxEdit = CType(c, ComboBoxEdit)
' AddHandler cb.SelectedIndexChanged, AddressOf SetIsDirty
'End If
' If c.Controls.Count > 0 Then
' AddDirtyEvent(c)
' End If
Next
is_Dirty = False
End Function
Private Sub SetIsDirty(ByVal sender As System.Object, ByVal e As System.EventArgs)
is_Dirty = True
ribButtonLicenseEditorSave.Enabled = True
ribSaveServerDetails.Enabled = True
If TypeOf sender Is ComboBox Then
Dim o As ComboBox = CType(sender, ComboBox)
Debug.Print("Is Dirty: " & o.Text)
'RemoveHandler oListOfDirtyHandles.TextChanged, AddressOf SetIsDirty
ElseIf TypeOf sender Is CheckBox Then
Dim o As CheckBox = CType(sender, CheckBox)
Debug.Print("Is Dirty: " & o.Text)
End If
End Sub
Sub RemoveHandlers()
For Each oListOfDirtyHandles As Control In lstHandlersToCleanUp
If Not oListOfDirtyHandles Is Nothing Then
If TypeOf oListOfDirtyHandles Is ComboBox Then
RemoveHandler oListOfDirtyHandles.TextChanged, AddressOf SetIsDirty
ElseIf TypeOf oListOfDirtyHandles Is CheckBox Then
Dim tb As CheckBox = CType(oListOfDirtyHandles, CheckBox)
RemoveHandler tb.CheckedChanged, AddressOf SetIsDirty
ElseIf TypeOf oListOfDirtyHandles Is DateTimePicker Then
Dim tb As DateTimePicker = CType(oListOfDirtyHandles, DateTimePicker)
RemoveHandler tb.ValueChanged, AddressOf SetIsDirty
ElseIf TypeOf oListOfDirtyHandles Is TextBox Then
Dim tb As TextBox = CType(oListOfDirtyHandles, TextBox)
RemoveHandler tb.TextChanged, AddressOf SetIsDirty
ElseIf TypeOf oListOfDirtyHandles Is RadioButton Then
Dim tb As RadioButton = CType(oListOfDirtyHandles, RadioButton)
RemoveHandler tb.CheckedChanged, AddressOf SetIsDirty
End If
End If
Next
End Sub