473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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
7 1423
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
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
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
Hi,

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

Thanks!

M O J O
Nov 21 '05 #5
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas | last post by:
Hy dudes, I have a strange problem. I dynamically create an IFrame with JavaScript and then fill in some content. Afterwards I want to switch to designMode. There the trouble starts. In Mozilla...
2
by: Lecture Snoddddgrass | last post by:
Hi, When I create a UserControl-derived object, I often expose various public properties. One of the things that I hate about the WinForms designer is that if I decide to embed one of these...
1
by: Tiago Barbutti | last post by:
I have a UserControl that execute methods in Load event, but it hapens in designMode and generate an error and the control disappear from the form. I read that i can use the DesignMode to kwnow...
2
by: Malleier Alfred | last post by:
Hi, what does the Me.DesignMode-Property turn back. I tried to set a MsgBox(Me.DesignMode) in my form's and control's Sub New(), but it allways turns back 'false', even if the form or control is...
29
by: Charles Law | last post by:
Further to my issue about user controls, I have a problem with DesignMode. Here is the project hierarchy: MainApp |_ Project1 |_ SubProject (UserControl) SubProject has a default constructor...
1
by: Paul W | last post by:
I'm having trouble detecting whether my Control is in DesignMode. I'm deriving a class from TreeView; Public Class ExplorerView Inherits TreeView ... End Class
2
by: Simon Rigby | last post by:
Hi folks, I'm trying to switch an iFrame in and out of design mode by way of a script. As you can see from the method it is intended to be cross browser compatible (or FF and IE at least). The...
4
by: Kyjan | last post by:
Greetings! In doing some research, I've learned that some other people have had problems with Me.DesignMode not working correctly when it's used in a user control that is placed on another form....
2
by: graeme g | last post by:
ii i've been developing some usercontrols... and sudden the property designmode no longer works.. if i test it value at designtime it always comes back false... i've made a work around if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.