Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am creating a component (Inherited from System.ComponentModel.Component instead of a UserControl). The problem is that I need to put some code in the Sub New() that should only be run at runtime. All well and good I say to myself... good case for a Designer. Only problem is that to make the Designer I need it to derive from UserControl. I don't need or want a visual interface for the control other than setting properties at design time. I want it to appear in the component tray.

 

I have read divils tutorial on Designers and have even implemented them in the past with other controls I have made. I am stumped at the moment though on how to do this with a Component. I would appreciate any help I can get.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted (edited)

Ok... evidently nobody knows that one. LOL

 

That is fine. I found the what looks like the solution to the problem but it has raised another problem it seems.

 

The evident solution is the DesignMode property of UserControls and Components. As a test I made the following code in the Sub New() of an empty component:

 

        If Me.DesignMode = False Then
           Throw New Exception("This should only be seen at runtime.")
       End If

 

It would seem that if DesignMode = False then that means that it is NOT in design mode. I then built the control, added it to the toolbox, then added it to a test form. As soon as I added it I got the exception thrown. That shouldn't have happened. So I changed the If statement to check for a True value. Sure enough it didn't get thrown this time... but neither did it during runtime. I did some stepping through of code and found out that the DesignMode property doesn't even seem to appear at runtime.

What this seems to mean is that:

 

a) The booleans are backwards.... DesignMode = True seems to mean that it is in Runtime not in DesignMode.

 

b) Since the DesignMode property isn't available at all in Runtime mode it is always looked at as being False once you are in a running program.

 

Maybe I am doing this wrong. Any help is appreciated.

Edited by mooman_fl

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • *Gurus*
Posted

You will have to rethink your design, as you cannot tell if something is being run in design mode from the constructor.

 

You can apply a designer to a component, you just have to derive your designer from ComponentDesigner instead of ControlDesigner.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...