471,066 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to know when a control is added to the form in Design

Is it possible to know when a control is added to a form in Design time?

I tryed with ControlAdded, but this is also fired when the program starts.

I want to set some properties only when a control is added to the form and
not when the program starts.

Thanks all.

Skysurfer
Dec 4 '07 #1
6 1434
On Dec 4, 9:21 pm, "Skysurfer" <skysurfer72TOGL...@libero.itwrote:
Is it possible to know when a control is added to a form in Design time?

I tryed with ControlAdded, but this is also fired when the program starts.

I want to set some properties only when a control is added to the form and
not when the program starts.

Thanks all.

Skysurfer
I wonder where you are planning to write your code ? At design time,
when you drag and drop a control, object of the same is created in
background. So the control is already added to the form.
What do you mean by design time ? What actually you want to do ?
Dec 4 '07 #2
I created a form, call it MyForm, and I want to use it as a base for all my
forms.
When i drag some controls on a form that inherits from MyForm, i want to set
some properties of the control.
If the control that I drag to the form has a property named
"VisualStyleManager", i want to set this property with a particular value.
Thanks
"coolCoder" <an*********************@gmail.comha scritto nel messaggio
news:0c**********************************@r60g2000 hsc.googlegroups.com...
On Dec 4, 9:21 pm, "Skysurfer" <skysurfer72TOGL...@libero.itwrote:
>Is it possible to know when a control is added to a form in Design time?

I tryed with ControlAdded, but this is also fired when the program
starts.

I want to set some properties only when a control is added to the form
and
not when the program starts.

Thanks all.

Skysurfer

I wonder where you are planning to write your code ? At design time,
when you drag and drop a control, object of the same is created in
background. So the control is already added to the form.
What do you mean by design time ? What actually you want to do ?

Dec 4 '07 #3
A form has a property called DesignMode, this is set to true when in
design mode.

You can handle the ControlAdded event and just simply check this
property to know whether it is design mode or not.

Dec 4 '07 #4
"Olie" <ow****@gmail.comha scritto nel messaggio
news:5a**********************************@d27g2000 prf.googlegroups.com...
>A form has a property called DesignMode, this is set to true when in
design mode.

You can handle the ControlAdded event and just simply check this
property to know whether it is design mode or not.
If I close the form and re-open it, always in Design, the property
DesignMode is True, so the property initialization is fired.
The problem is that if I change the Property, I close the Form, and i open
it again, my property is overwritten with the property in ControlAdded.

Bye

Skysurfer
Dec 4 '07 #5
I am not sure but I think the problem is that you changes are getting
overridden with the code behind property values. You will find that in
design mode Visual Studio stores a copy of the properties and sets
them when the form starts up. If you set them in code before
InitialiseComponents then they will get overridden.

Not entirely sure what you meant from your post and got a bit confused
as to when you where in design mode.

Dec 4 '07 #6
On Tue, 04 Dec 2007 16:21:35 GMT, "Skysurfer"
<sk****************@libero.itwrote:
>Is it possible to know when a control is added to a form in Design time?

I tryed with ControlAdded, but this is also fired when the program starts.

I want to set some properties only when a control is added to the form and
not when the program starts.

Thanks all.

Skysurfer
Controls that are part of the form are added in the
InitializeComponents method. Add a Sub New to your form and the IDE
will add a call to InitializeComponents in that method. Create a
form level Boolean field that is initially set to False. Set it to
True in New() after the call to InitializeComponents(). In your
OnControlAdded method the field will be True for controls added by the
user.
Dec 4 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Lucas Sain | last post: by
1 post views Thread by Tony Johansson | last post: by
11 posts views Thread by Rimpinths | last post: by

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.