|
-
May 10th, 2005, 02:41 AM
#1
quick help require on static controls!!!
Hi to all,
I m working on VS .net making forms for my project using C# but i m facing a very big problem and that is that i need some controls on my forms to be static as i have to use those controls on other forms as well but as static property for modifier in controls is not there so i have to change the code for those controls from private to public static , removing this. keyword where ever this control is used and some other changes in the code as well accordingly but as soon as i switch to the design mode of form the chages i made in the code rollback again to non static controls from public static to private or public only for example i have a button as:
private System.Windows.Forms.ToolBarButton btnConnect;
as i want this button to be static so i have to change code like
public static System.Windows.Forms.ToolBarButton btnConnect;
and remove this. keyword where ever this button is used
but as soon as i switch to the design mode for adding some more controls or making some changes this control will again become non static as
public System.Windows.Forms.ToolBarButton btnConnect;
and this. is as well added where ever this control is used
as i want nearly all controls of the forms to be static and it is so hard for changing the code again and again after every change in the form. Isn't there any way that the controls remain static and the chages in the form design wont affect this?
I hope i get a quick response....
Thanks
Usman,
Islamabad, Pakistan
-
May 10th, 2005, 02:48 AM
#2
Re: quick help require on static controls!!!
i need some controls on my forms to be static as i have to use those controls on other forms as well
Sorry, I have no idea what you are trying to do, this does not make sense.
A control can only belong to one instance of a Form/Control at any one time. ie it can only have one parent.
Why do you need "global" access to a control? Why not simply access it through the instance of the Form that has it?
Useful? Then click on (Rate This Post) at the top of this post.
-
May 10th, 2005, 03:27 AM
#3
Re: quick help require on static controls!!!
It doesn't make sense to me either, but if you want static controls I suggest that you don't create them via the designer, instead create them directly in code. Tampering with the designer generated code is not a good idea, just as you experienced it the designer can modify the code and there is no way for you to prevent it. The declaration of controls created in the designer is also designer generated, even though the designer not writes any comments about that.
In c# 2005 it will become more clear which code you can modify and which you not should touch, since partial classes are introduced.
-
May 10th, 2005, 06:28 PM
#4
Re: quick help require on static controls!!!
what is this magical form ur making?
controls arent static.
but you can make the handler static. easy.
-
May 10th, 2005, 10:49 PM
#5
Re: quick help require on static controls!!!
Hi,
I was not trying to create any magical form .But I think that was a mistake..when i got the first reply...I myself thought that i was wrong. Controls can not be static in design ....... Although I pay thanks to reply such bad question!!
Usman,
Islamabad, Pakistan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|