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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Delete Public Static Declaration

Status
Not open for further replies.

vtops

IS-IT--Management
Oct 13, 2005
63
GR
Dear All,

I am facing the following problem and i don't know if it's a bug or it's just an adjustment.

I am using Visual Studio .Net 2003. If on a form i have declare some objects as public static and do some modification on the objects of this form (move objects,delete objects,insert new objects) then automatically the declaration public static is replacing by public.
Can i do something about that?

Best Regards
 
If you declared the static, object modifications will restrictedselect approoriate modifications that are go along with static..
 
Yes I have declared some textboxes and some
checkboxes as public static in order to control them from another form.
But if i do any modification on the form which contains the public static objects (it doesn't matter if the modifications are on the specific objects or to other objects then automatically the public static declaration will be replaced from public)

Thank you.
 
I can't see why you would ever want to make them static.

What you need to do is expose some methods that will allow you to set the values of your checkboxes on an instance of a form, or set the value that the checkbox or textboxes represent in some kind of controller that your form reacts to.

Look into Model View Controller (MVC) design pattern on google.
 
Yeah, you wouldn't ever change the access level on the control declaration -- you'd add a static method (that accepted an instance of your form) that would manipulate it for you.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi All,

I am new in C#

How can i add a static method which will accept the instance of a form?

Please help me!




Best Regards
 
This will do it. You pass an instance of the class as a parameter to the static method call.
Code:
public class MyClass
{
  public int SomeValue;

  public static void AcceptInstance(MyClass myClass)
  {
     myClass.SomeValue = 31;
  }
}
To call it:
Code:
{
   // Create instance
   MyClass m1 = new MyClass();

   // m1 now has 0 as it's SomeValue member
   Console.WriteLine(m1.SomeValue);

   // Call the static method
   MyClass.AcceptInstance(m1);

   // m1 now has 31 as it's SomeValue member
   Console.WriteLine(m1.SomeValue);
}
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top