What event should I handle to execute the code when the WinForms application switches from run mode to development mode
I am running a Windows Forms application and I need to execute a piece of code when I switch to design mode. I have a handler for the debugger's OnEnterDesignMode event and this gets hit if I debug an application and then switch to design mode. However, it doesn't hit if I initially run without debugging and then switch to development mode. What event do I need to handle to execute certain code when going from run mode to development mode?
a source to share
Not sure about the event, but there is a DesignMode bool property on the Windows form, probably inherited from Control, which returns true if the form is open in the designer. Remember that because DesignMode returns false in the designer even in design mode. So always use it in something like a load event and not in a constructor.
a source to share
Try Component.DesignMode in your control. See MSDN
VB.net example
Private Sub txtSmartDate_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSmartDate.TextChanged
If Not Me.DesignMode Then
If _ValueInitialised And Not _SuppressEventCode Then
' Apply the changes to the property value, now the text box has been updated.
Call SetPropertyValues()
Call ApplyDateFormating()
End If
End If
End Sub
a source to share