Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is there a way that i may find out if a control is drawn during run-time or design time?

I was considering some playing around with the sub new method but that won't work.... there has to be to do it somewhere in this framework.

I've looked aroudn in the Reflection Namespace but have had no luck.

 

I'm trying to create a control design interface when a control i have designed is dropped on the form.

the idea is very simple...

If the control is dropped on a form during design time... give the user an option of of using a custom form designer to dictate the properties for the new control

if the control is added during runtime however i would like this feature dropped an automatically added to a form

 

the idea is virutaully identical with dropping a DataAdapter on a form and using it's form designer.

 

any ideas to this one will be very appreciated

i'm not lazy i'm just resting before i get tired.
Posted

are you sure it doesn't work in the constructor? it seems to do fine.. although i havn't tested it yet.

if you are correct do you mind a brief explanation of why this property won't work in Sub New()?

 

if sub new doesn't work will this defeat it's purpose in my case?

all of my initialization occurs in Sub New() and i would like to check the DesignMode property just before i initialize anything.

 

I think i'm going to start a divil fan club.

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

The DesignMode property on a component echoes the DesignMode property of the ISite associated with a component. A component only gets an ISite once it has been sited on a surface, which obviously cannot be done until it's been instantiated - i.e. after the constructor has run. If the component does not yet have an ISite associated with it, the DesignMode property simply returns false.

 

If you are wanting to intitialize object only at design time, I'd suggest you do so in a designer for the control. It's best to keep things separate like this, that way your control has as little design time code running at runtime as possible.

MVP, Visual Developer - .NET

 

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

 

My free .NET Windows Forms Controls and Articles

Posted

However this doesn't help you with the task to find out *at runtime* whether a control was created at designtime or at runtime.

 

Since I didn't want to inherit all relevant controls (and add an extra property) I used the .Tag property and "left a note" there, for controls created at runtime.

 

Anyone with a better solution?

.nerd
  • *Gurus*
Posted
I can't for the life of me imagine any situation where one would need to differentiate between the two. The whole point is that they behave exactly the same whether you create them in code or the designer creates the code to create them in code :P

MVP, Visual Developer - .NET

 

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

 

My free .NET Windows Forms Controls and Articles

Posted

We have this situation here. Your life is mine then, hehe.

 

We have "parameterdriven" controls, which are being read from a database. however, as this will lead to rather bad UI design, the developer may also position the parameterdriven controls on their respective containers at designtime.

 

now, if the context switches, I need to remove the controls that were added at runtimt and keep those that were added at designtime.

 

He.he.

 

Can I have your soul too?

.nerd
Posted

All this seems to be getting rather confusing...

I'd like to restate my purpose real quick.

During my control's instantiation i'd like to determine run-time or design-time at that moment... it seems DesignMode won't allow me to do that.

AHHHH BUT WAIT I JUST HAD AN IDEA...

the Paint event is called after Sub New correct?

if this is so... then i may use the following code to produce a designer for my control this way

 

Overrides Sub Paint(sender as object, e as painteventargs)

If Me.DesignMode = True Then

'ShowCustomDesigner

End If

 

is this the solution to my problem? i think i got it figured out...

but i'm sure you one of you will shoot it down rather quickly :)

 

BTW if anyone gets divil's life it's me... but i'll just take his brain and you can have the rest.

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

Hey! Don't I get a say in how I'm divided? :P

 

Anyway - I wouldn't rely on the Paint event for what you need to do. What would probably best is making a designer for your class (see my article, Introduction to Designers) and in the overridden Initialize method of that class, you can call back to the main control to tell it to initialize design-time objects.

MVP, Visual Developer - .NET

 

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

 

My free .NET Windows Forms Controls and Articles

Posted

yes i read that maybe 2 mintues after my post... very interesting..

 

i'm glad you posted that site... i'll use that in the near future

i'm not lazy i'm just resting before i get tired.
Posted

What about the Initialize member in ControlDesign class?

I'm gonna play with it for a little bit... i think that might be the one.

Interested in your thoughts/experiences

 

I noticed i could use a verb to do it but, that's not quite what i'm looking for. I'd like to provide the user with form that let's them choose a from a few options for the setup of my control. I know this seems like something that should be done during run-time... but i feel this would be more user friendly than a giant parameter list.

i'm not lazy i'm just resting before i get tired.
Posted

Using Initialize in the Designer Class worked great..

a funny thing happened though... i forgot to code my form that i displayed the first time and there was no control box on it either... so when the form popped up it was stuck on the screen. I had to close VS to get rid of it lol

ohh and i'm using a verb as well to do it, so the user may do it at either time.

i'm glad you posted that in your site. it was exactly what i needed

i'm not lazy i'm just resting before i get tired.
Posted

I agree that the tutorial makes the concept easy to grasp. I am still having trouble though. I am trying to implement a designer in my own control project that I was already working on. Below is the code that I added to this project to start a designer for it (code for the control is collapsed since it should be unecessary for this example):

 

Imports System.Windows.Forms.Design
Imports System.ComponentModel

+  <Designer(GetType(ToolPanelDesigner))> Public Class ToolPanel...

-  Friend Class ToolPanelDesigner
      Inherits ControlDesigner

  End Class

 

 

The problem is that "ControlDesigner" is underlined in blue and the tool tip says it is not defined. Everything else seems to be ok. What am I missing? Just for reference I tried cutting and pasting the example code on divil's tutorial to a new project and got the same thing. (I am using Enterprise Architect)

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

Ok... that did the trick. LOL

 

Pretty basic and I have done that type thing before. Now I will know what someone means when they say add an Assembly reference. LOL

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

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...