By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,693 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,693 IT Pros & Developers. It's quick & easy.

Propper way to find out if I'm in DesignMode?????

P: n/a
Hi,

I can't figure out how to use the DesigMode property. I've searched Google
and not found a soilid solution. Therefor I ask you - what is the propper
way to find out if I'm in DesignMode???

Here's my test code - I'm trying to inheriting the textbox, so when I place
it on my form, I want the backcolor of the texbbox to change to yellow....
Public Class MyTextBox
Inherits System.Windows.Forms.TextBox

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

If Me.DesignMode Then
Me.BackColor = System.Drawing.Color.Yellow
Else
Me.BackColor = System.Drawing.Color.Red
End If
End Sub

'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

#End Region

End Class


The only solution I found was to use the function instead of DesignMode:

Private Function MeInDesignMode() As Boolean
MsgBox(Process.GetCurrentProcess.ProcessName)
Return Process.GetCurrentProcess.ProcessName.ToLower = "devenv"
End Function

..... but I don't think this is a solid solution.
Any ideas?????

Thanks!

M O J O
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi,

I think the DesignMode will work when we are in the design view of the IDE,
e.g. when we drag a usercontrol onto a form.
You may try as below.
1. Create a new usercontrol and handle the load event as below
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Me.DesignMode Then
MsgBox("Now the control is in design mode")
End If
End Sub

2. Build the usercontrol
3. Create a new winform application and drag the usercontrol onto the form
4. at this time, the messagebox will be pop up which shows "Now the control
is in design mode".

But in runtime, i.e. when we run the winform application, the dialog will
not pop up.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2

P: n/a
Hi Peter,

No, the DesignMode always returns false.

Please look at my MyTextBox example.

Since I'm inheriting from a TextBox, I do not have a Load-event.

Kind regards,
M O J O

""Peter Huang"" <v-******@online.microsoft.com> skrev i en meddelelse
news:Lo**************@cpmsftngxa06.phx.gbl...
Hi,

I think the DesignMode will work when we are in the design view of the
IDE,
e.g. when we drag a usercontrol onto a form.
You may try as below.
1. Create a new usercontrol and handle the load event as below
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Me.DesignMode Then
MsgBox("Now the control is in design mode")
End If
End Sub

2. Build the usercontrol
3. Create a new winform application and drag the usercontrol onto the form
4. at this time, the messagebox will be pop up which shows "Now the
control
is in design mode".

But in runtime, i.e. when we run the winform application, the dialog will
not pop up.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #3

P: n/a
Don't put it in the NEW sub. Put it somewhere else.

"M O J O" <mojo@_no_spam_delete_this_newwebsolutions.dk> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
Hi Peter,

No, the DesignMode always returns false.

Please look at my MyTextBox example.

Since I'm inheriting from a TextBox, I do not have a Load-event.

Kind regards,
M O J O

""Peter Huang"" <v-******@online.microsoft.com> skrev i en meddelelse
news:Lo**************@cpmsftngxa06.phx.gbl...
Hi,

I think the DesignMode will work when we are in the design view of the
IDE,
e.g. when we drag a usercontrol onto a form.
You may try as below.
1. Create a new usercontrol and handle the load event as below
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles MyBase.Load
If Me.DesignMode Then
MsgBox("Now the control is in design mode")
End If
End Sub

2. Build the usercontrol
3. Create a new winform application and drag the usercontrol onto the
form
4. at this time, the messagebox will be pop up which shows "Now the
control
is in design mode".

But in runtime, i.e. when we run the winform application, the dialog will
not pop up.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.


Nov 21 '05 #4

P: n/a
Hi,

I can't figure out where to put it then. Any suggestion?

Thanks!

M O J O
Nov 21 '05 #5

P: n/a
Hi,

Yes, the DesignMode did not work in the contructor. Because the textbox did
not have onload method, we can detect the designmode in other function
after contructor.
You may try the code below in your userdefined textbox.
Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
If DesignMode Then
Me.BackColor = System.Drawing.Color.Yellow
Else
Me.BackColor = System.Drawing.Color.Red
End If
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

P: n/a
Hi Peter,

Thank you!!! This seamed to work!

M O J O

""Peter Huang"" <v-******@online.microsoft.com> skrev i en meddelelse
news:e7**************@cpmsftngxa06.phx.gbl...
Hi,

Yes, the DesignMode did not work in the contructor. Because the textbox
did
not have onload method, we can detect the designmode in other function
after contructor.
You may try the code below in your userdefined textbox.
Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
If DesignMode Then
Me.BackColor = System.Drawing.Color.Yellow
Else
Me.BackColor = System.Drawing.Color.Red
End If
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #7

P: n/a
Hi,

I am glad that that worked for you.
Cheers.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.