|
:|everything is encapsulated inside objects. that being the case, no there are no global variables in .net.
you can make "global" variables with a singleton object:
public class Global {<br />
private static object syncLock = new object();<br />
private static Global instance;<br />
public static Global Instance {<br />
get {<br />
lock(syncLock) {<br />
if(instance == null) instance = new Global();<br />
}<br />
return instance;<br />
}<br />
}<br />
private Global() { <br />
one = 1;<br />
two = false;<br />
er = 0.2F;<br />
} <br />
private int one;<br />
private bool two;<br />
private float er;<br />
<br />
public int One { get { return one; } set { one = value; } }<br />
public bool Two { get { return two; } set { two = value; } }<br />
public Float Er { get { return er; } set { er = value; } }<br />
}<br />
<br />
<br />
<br />
Global.Instance.One = 7;<br />
<br />
<br />
int oneVal = Global.Instance.One;
STABd
|
|
|
|
|
You can use a global variable by declaring it as static member of the class. e.g
public static int var;
now the variable 'var' will be used as global variable.
Regards
sAqIb
|
|
|
|
|
Hi all,
I have created an windows application, now i want to embed this
application in a web browser.
The first question is whether this is possible?
and if possible, how do i do that?
Please direct me to some good source for the same.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
As far as I know that is not possible (99.99% shure).
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
|
I heard something as "Click-Once" that allows you to use those Forms as Java applets in the web.
|
|
|
|
|
Hi,
I've been looking for like 2 hours for a method or anything that reads the text which is typed in a textbox.
I don't really know much about buttons and textfields. I usually work with the console.
Can anyone tell me how to read in text from a textbox plz?
Thanks in advance!
|
|
|
|
|
suppose that u want to retrieve the data of the textbox to a variable
u can do it by the foll code:
string data=textboxname.Text;
NEHA GUPTA
|
|
|
|
|
hi
textBox1.text will give you the text is typed in textBox1
Tamimi - Code
|
|
|
|
|
Hi Tamimi,
That worked! Thank you!
I declared readIn to read what is typed in the textbox like this:
string readIn = this.texBox1.Text;
And attaching it to the eventhandler like this:
readIn += new KeyEventHandler(texBox1_KeyPress);
It gives me the error:
No overload for 'texBox1_KeyPress' matches delegate 'System.Windows.Forms.KeyEventHandler'
What am i doing wrong?
|
|
|
|
|
hi
could you give more details about what you are trying to do ??
if simply you want the text in a textbox the .Text property its enough
and no need to attaching anything.
what exactly you want to do ??
Tamimi - Code
|
|
|
|
|
Hi,
I want to accept only 0, 1, 2 .... 9 as input. In order to do this, i have to attach texbBox1.Text to the keypressed handler.
But i got it fixed now,
Thank you!
|
|
|
|
|
hi
is there any wrong with this:
private void textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e) { int intKeyValue = (int)e.KeyChar; if (((intKeyValue<48 || intKeyValue>57 ) && intKeyValue!=46)) { e.Handled = true; } }
Tamimi - Code
|
|
|
|
|
Hi Tamimi,
There is nothing wrong with that method.
In fact, thats the eventhandler i was trying to attach 'readIn' to.
If a key is pressed 'readIn' will call that eventhandler to check if its a valid one.
Sorry for the confusion Tamimi!
|
|
|
|
|
hi
are you trying to do this:
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
if not feel free to ask again
Tamimi - Code
|
|
|
|
|
Hi Tamimi,
Thats exactly what i meant. But i fixed that half an hour ago
I do have another question...
If i want to get everything between 2 chars, how would i do that?
Example:
[1]
[12]
[123]
How would i get everything between the '[ ]' chars?
Substring wont help, coz the characters inside the [] can be sometimes 1, 3 or more.
Thanks in advance!
|
|
|
|
|
hi
try this:
int intStartIndex = textBox1.Text.IndexOf("[") + 1;
int intEndIndex = textBox1.Text.IndexOf("]") - 1;
string strBetween = textBox1.Text.Substring(intStartIndex,intEndIndex);
but you should be sure that the chars "[" and "]" are exists if not you will get an error index or something like this
Tamimi - Code
|
|
|
|
|
Hi Tamimi,
That worked great!
I thank you for all your help and patience!
Yustme
|
|
|
|
|
you are welcome
Tamimi - Code
|
|
|
|
|
You could also try using the textchanged event of the textbox.
He who laughs last is a bit on the slow side
|
|
|
|
|
Hi,
I have a radio button on my windows form and I want this to be databound to a binding source.
Ok, now it is very easy to set the CHECK State of the radio button to bound to a BIT data type of SQL. But what if I want to add some custom code for the CHECK STATE and the custom code uses the other type of data field from the SQL ? IS is possible ?
Example : I may have a varchar field in SQL which is named "fieldType". Now I want to add the following constraint,
Databound CheckState should be checked if(fieldType == "abc")
otherwise CheckState should be non Checked.
Thanks and regards
|
|
|
|
|
how shutdown the system in c#.net 2005
how to use the initiatesystemshutdown Function in c#.net 2005
|
|
|
|
|
use dllImport atribute to export the API from user32 or kernel32,check out in API viewer
and call the fuction...
eg,
import like this.
[DllImport("kernel32")]
private static extern int InitiateSystemShutdown(,,,);
nishu
|
|
|
|
|
Hi
i want to view a .ini file through c#. can anybody help me to write code for it? i mean i just want to know how to open a .ini file to show it to user.
Regards
sAqIb
|
|
|
|
|
Hi,
There is one programme in codeproject which changes the folder icon,which acctually changes the desktop.ini file ,go through that programme just search in codeproject about it like "changing folder icon".you wil get your answer .enjoy man.
|
|
|
|