I am running a Windows form application and I need to execute a piece of code when I switch to design mode. I have a handler for the OnEnterDesignMode debugger event and this gets hit if I am debugging the application and then switch to design mode. However, this does not get hit if I initially start without debugging and then switch to design mode. What event do I need to handle in order that certain code is executed when switching from Run mode to Design mode?
views:
102answers:
3
A:
Are you referring to release mode and debug mode?
If so you can wrap your code as follows:
#if DEBUG
//Execute debug mode code
#else
//execute release mode code
#endif
Jason Heine
2010-05-10 14:40:06
A:
Not sure about the event, but there is a DesignMode bool property on a windows form, probably inherited from Control, that returns true if the form is open in the designer. Beware though, as DesignMode returns false in a constructor even when in design mode. So always use it in something like the load event, and not in the constructor.
Jacques Bosch
2010-05-17 05:04:30
A:
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
Jamie Clayton
2010-05-18 08:15:09