Unwanted Event firing
-
Hi I have a composite (complex) CustomControl in VB.NET. In the *.Designer.vb file a control is set to a Settings value:
Me.nudtags.Value = Global.Project1.My.MySettings.Default.pastags
I suspect this fires the ValueChanged event (even though the Designer.vb file calls Me.SuspendLayout?)Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged DoMethod(nudtags.Value) End Sub
The "DoMethod" can not run in design-time, but it fires and runs as soon as I add the control to a form (in the same project). There must be a way to prevent this event from firing in design time and/or after the CustomControl is loaded in runtime? :confused: PS: I triedMe.DesignMode
but with no luck. -
Hi I have a composite (complex) CustomControl in VB.NET. In the *.Designer.vb file a control is set to a Settings value:
Me.nudtags.Value = Global.Project1.My.MySettings.Default.pastags
I suspect this fires the ValueChanged event (even though the Designer.vb file calls Me.SuspendLayout?)Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged DoMethod(nudtags.Value) End Sub
The "DoMethod" can not run in design-time, but it fires and runs as soon as I add the control to a form (in the same project). There must be a way to prevent this event from firing in design time and/or after the CustomControl is loaded in runtime? :confused: PS: I triedMe.DesignMode
but with no luck.There is no way to stop an event from firing. you just have to get creative in the method you handle it at different times. The ValueChanged event fires because, well, the value changed. The Value has nothing to do with SuspendLayout. Normally, the value would be used as design time, as well as runtime, to update the visuals of the control in the designer. If you wanted to not run the DoMethod, I'd do something like this:
Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged
If Not DesignMode Then
DoMethod(nudtags.Value)
End If
End SubI've heard of DesignMode not being reliable, though I've never had aproblem with it. You might want to read this[^] for some clarifications.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
There is no way to stop an event from firing. you just have to get creative in the method you handle it at different times. The ValueChanged event fires because, well, the value changed. The Value has nothing to do with SuspendLayout. Normally, the value would be used as design time, as well as runtime, to update the visuals of the control in the designer. If you wanted to not run the DoMethod, I'd do something like this:
Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged
If Not DesignMode Then
DoMethod(nudtags.Value)
End If
End SubI've heard of DesignMode not being reliable, though I've never had aproblem with it. You might want to read this[^] for some clarifications.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007I tried exactly what you had there before posting the question. That
DesignMode
for some reason returnsFalse
. Thanks for the reply. I think that article will be a help... For now I have worked around it with my own designmode boolean I set to false during runtime :)