473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Static controls

hi,

i have some controls in a form which are declared as static

for example :-

public static System.Windows.Forms.ComboBox comboBox1;

it is working fine and i am able to access the control from other forms
without creating an object of it. But when i make any changes in the form
like adding another control, the access modifier is disappearing.

i.e. my code becomes

public System.Windows.Forms.ComboBox comboBox1;

can anybody tell why this is happening and a solution

Thanking You
Nov 17 '05 #1
2 3184
Hi,
You should not create a control static, change the modifiers property to
"Public" in order to acccess from another form.

cheers
Salva
"Dhanraj K" wrote:
hi,

i have some controls in a form which are declared as static

for example :-

public static System.Windows.Forms.ComboBox comboBox1;

it is working fine and i am able to access the control from other forms
without creating an object of it. But when i make any changes in the form
like adding another control, the access modifier is disappearing.

i.e. my code becomes

public System.Windows.Forms.ComboBox comboBox1;

can anybody tell why this is happening and a solution

Thanking You

Nov 17 '05 #2
Hi,

Do this, put the declaration of the cntrols in a separate #region ( Just for
organization, not really needed ) , then go to the InitializateComponent and
cut all the lines where these controls are used and paste it in the
constructor AFTER the call to InitializateComponent() , in this way the
designer will not overwrite them , if you have more than one constructor you
should create a separate method instead.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Dhanraj K" <dh*******@hotmail.com> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...
hi,

i have some controls in a form which are declared as static

for example :-

public static System.Windows.Forms.ComboBox comboBox1;

it is working fine and i am able to access the control from other forms
without creating an object of it. But when i make any changes in the form
like adding another control, the access modifier is disappearing.

i.e. my code becomes

public System.Windows.Forms.ComboBox comboBox1;

can anybody tell why this is happening and a solution

Thanking You

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: .pd. | last post by:
Hello, If I have a static control and 2 forms, each of which references the static. When I return from the 2nd and go back to the first, the reference to static control appears to have been...
8
by: Cybertof | last post by:
Hello, I have a simple question : In the below code, why do i get an (ERROR) saying "An object reference is required for the nonstatic field, method, or property 'mLockeEnv3'" I don't...
2
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the...
1
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To...
3
by: Doug Handler | last post by:
I have a static method that needs to assign a type to an instance of an object. What's the best way to address this? e.g. private Panel pnlMain = new Panel(); ..... public static void...
1
by: Nadav | last post by:
hello, I have a form, with some controls I decided to define as static. Every time I change something in the form's design, InitializeComponent() is re-written and screws up the static...
1
by: uday | last post by:
hi all, i want to Increase the Font of the Labels before all the Controls. is there any approach to increase the Font of a Static Control that we palce before all the Controls to Identify. i...
7
by: Jon Slaughter | last post by:
I have some static fields in a class to keep track of "global" information but this information is local to each form that the class is used on. e.g., the class represents a base...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
0
by: Mahmoud Al-Qudsi | last post by:
Hi all, What is the recommended way of binding controls to a *static* datasource? In my project, I have to use the same ADO.net data source/ bindingsource in mulitple forms and across...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.