Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Controls

Status
Not open for further replies.

Proqrammer

Programmer
Sep 17, 2006
64
Hi there,

I have some user controls in my project, how can I know if the user control is being executed under design mode or if it's the compiled application that is using my user control?

I want my user control to look differently when it's in design mode how can I do that?

 
It might be just me but...... I really don't understand what you're talking about.
Could you give more detail on what you're trying to do and what is causing the problem?

---
If gray hair is a sign of wisdom, then talk like a pirate ninja monkey if you get the time to get funky once a week.
Wo bu zhi dao !
 
Yes sure, Ok here is the long story,

Once something really crazy happened to our project, I had a form in my solution and when I was clicking on it, in solution explorer tab, visual studio.net was shutting itself off. That was one of the weirdest things in my programming life.

I tried to find what the problem is, and I succeeded, I had some user controls in my form, those user controls were using the database class that I have made for my application, When you use a user control in your form, and when you are in design mode, dot net is actually compiling and executing your user control.

For example if you put a Msgbox("foo") in the Load event of your user control, and then you use that usercontrol in a form and try to see the design view of your form in vs.net, you are going to see a foo message event hough you haven't even built your application yet. You see what I mean?

I remember in ASP.NET I had encountered a similar problem, I had a usercontrol that was showing a calendar, now when that calendar was being shown to the user on a webpage, it must show a calendar, but when you are in vs.net and you are designing the form in which you want the calendar to show up, you don't want to see that calendar, but a simple textbox instead. There was a way of doing this by some xml tags in ASP.NET, I wonder if there is an equivalent for that in windows based applications.

In summary a control in .net has two interfaces, one is for design mode, and one is for run time mode, now how can we know in code that the control is being watched under the design mode or run time mode? Whom is this control being shown to? the user who has executed the application or the programmer who is using our user control in a developing IDE such as vs.net.

I hope that's more clear now.
Thanks

 

Hi,

try checking the DesignMode property of your control:

Code:
            If Me.DesignMode Then
                MsgBox("I am in design mode")
            Else
                MsgBox("I am in runtime")
            End If


Hope it solves the problem.

---
If gray hair is a sign of wisdom, then talk like a pirate ninja monkey if you get the time to get funky once a week.
Wo bu zhi dao !
 
Thanks, that works fine for the code, but how do I change the way my control looks at design time?

 
If you mean having the control display in a special way at design time then :

Code:
            If Me.DesignMode Then
                'Call the sub that suits your requirements
                ArrangeForDesignMode()
            Else
                'Call the sub that suits your requirements
                ArrangeForRunTime() 'If needed only
            End If

Or if you mean changing your control's properties at design time, well I don't see why you couldn't?


Hope it helps.


---
If gray hair is a sign of wisdom, then talk like a pirate ninja monkey if you get the time to get funky once a week.
Wo bu zhi dao !
 
Do you really have to do all that in .Net? It's automatic in VB6, like having the sizing handles on the control and all that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top