开发者

Using Generic Event Handler for Controls in Windows Forms!

I have bunch of controls which get populated from Database when the form Loads. I am using Dictionary (control.Name as Key and Control.Value as Value) to store inital values. When user changes v开发者_StackOverflow中文版alues I am using other Dictionary to load current values and compare it with inital Dictionary. If the values are different I am running some kind of code to prompt user of changes. I think it more hackish and looking for better solution. Please advise.

Thanks


try this

For Each ctrl As Control In me.Controls
            If TypeOf ctrl Is CheckBox Then
                AddHandler (DirectCast(ctrl, CheckBox).CheckedChanged), AddressOf Control_Changed
            ElseIf TypeOf ctrl Is TextBox Then
                AddHandler (ctrl.TextChanged), AddressOf Control_Changed
            ElseIf TypeOf ctrl Is NumericUpDown Then
                AddHandler (DirectCast(ctrl, NumericUpDown).ValueChanged), AddressOf Control_Changed
            End If

        Next

Sub Control_Changed(ByVal sender As Object, ByVal e As EventArgs)
        ' handle events here
    End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜