|
i need to store some variables withing one class and that class to be accessible all over my application with the specified common variables as the following
i need when i press button to take the text value from the textbox.text and store that value in global variable within a class which i will use in different forms within the same application .
In addition i tried alot but each time when i declare my class as the following
globalclass myclass = new globalclass();
this.username = myclass.username;
it gives me blank variable in username string
i guess that because i open new instance of that class
but i need to store variables and to be called whenever i want within my application with the variables stored in its places
Any help with that
Thanks .
Miss With The Best And Die Like The Rest
|
|
|
|
|
snouto wrote:
i need when i press button to take the text value from the textbox.text and store that value in global variable
I can't figure out what exactly you are doing wrong here. If you create a class with public variables or, even better, public properties, you shouldn't have problem using it across your forms and application. All you have to do is to create an object of that class and pass those members of it that you need to work with (or the whole object if you need it), as arguments to different classes across your application.
snouto wrote:
In addition i tried alot but each time when i declare my class as the following
globalclass myclass = new globalclass();
this.username = myclass.username;
it gives me blank variable in username string
What value do you initialize the username variable with? Also, what is this.username for? Do you wish to refer to a textbox on the form?
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
my friend i need to store the text box value into
the form username string which i declared in the class of the main form i need that username to be stored in the global class to be accessible with the value of the variable all over my application in different forms
Globalclass myclass = new Globalclass();
myclass.username = textbox.text;
and that myclass.username can be accessed from the globalclass in another form
Miss With The Best And Die Like The Rest
|
|
|
|
|
Ok, so what you are saying is that no matter what you type into the textbox, all you keep getting copied into myClass.Username is an empty string? In what event did you place this code?
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
please add me to your contact list
my email address is
matrix_623@yahoo.com
please add me and chat with me now on yahoo please iam waiting for you my friend
Miss With The Best And Die Like The Rest
|
|
|
|
|
The way to this is to :
Create a new class called GlobalVariables //for example.
And then add static members in it and just do:
//in global .
static string userName = "";
//In your form.
button1_Click()
{
GlobalVariables.userName = this.userName.Text;
}
//And just access it as easy as :
string reciever = GlobalVariables.userName;
without the need to initialize any thing.
|
|
|
|
|
The key to what you need is a concept of "static" members.
static members are those that are shared among all instances of a class and are declared using the static keyword.
You can access these static members by just using the classname of the containing class, instead of the variable name holding an instance for instance members.
You can even initialize these static members in the static class initializer that's executed when the class is first loaded by the CLR.
For example:
class MyGlobals
{
static string UserName;
static DateTime LogonTime;
static MyGlobals()
{
UserName = "Not set";
LogonTime = DateTime.MinValue;
}
} Then you can simply do this:
class MainProgram
{
public static void Main()
{
Console.WriteLine("Username is " + MyGlobals.UserName);
}
} This will give you "Not set" without any previous initialization in your MainProgram class.
Regards,
mav
|
|
|
|
|
Its a common situation.
Everybody is giving you advices like "make this field and property that static".. And its OK. But thinking in global I think you should use "Singleton pattern". That would be the most clear solution.
Best regards
p.p: What you mean with "Miss with the best".. wasn't it "mEss"?
|
|
|
|
|
I currently have a Server/Client setup using Asynchronous trasnferring of messages. I now want to add the ability for a client to send a file to the server, who then passed it to the client. I assume the best way to do this is using the existing Asynch model, but I might be mistaken. Anyone have any advice as to what would be the best/easiest way?
|
|
|
|
|
hi man how are you
please Add me to your yahoo contact list cause iam developing the same application and i did alot of progress and i want you to join me i had already did
1) multithreaded server .
2) multiple user connection.
3)login for users using database MS Sql 2000
4)Private chatting
5)General chatting
6)Webcam Broadcasting .
7)File transfer Options
//Sound is on the way so if you want to share with me the knowledge add me and you will be partner with me in my application thank you
Yours;
Snouto Override ......
Miss With The Best And Die Like The Rest
|
|
|
|
|
Hello!
I'm developing a windows service that is monitoring the filesystem, i need to make it write to a log BEFORE you open a file that the file is beeing opened. I can catch file change,rename,delete,create event, but i can't find anything for catching a "about to be opened" event. Anyone got suggestions?
|
|
|
|
|
In the event handler of the openning Write a call to a method that do this and when this method says that to the user, it will return and open the file.
|
|
|
|
|
hmm i'm not sure i understand.. i need to catch the event before the user opens any file in thefilesystem, to a service.. but from what i understand there is no such event in the api..
|
|
|
|
|
There is no "Opening" event.
Believe it or not, you'll have to write a file system driver. This is best done in C++ because of the HUGE amount of COM Interop your going to have to do in C# to get this to work. If done in C#, this will add quite an overhead to all file operations system-wide.
SysInternals FileMon does just this. You can find it here[^] with a short decsription of what it does and how. This is not easy if you don't know anything about HTFS internals, and as a side-note, will require you to get the Windows Device Driver Development kit which is only downloadable by MSDN subscribers. You can get it on CD though for a small fee.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I need to show the network performance just like Windows Task Manager’s Network Utilization. I am using PerformanceCounter class. It is working fine until I deploy my application on any other machine.
My code goes like :
this.performanceCounter.CategoryName = "Network Interface";
this.performanceCounter.CounterName = "Current Bandwidth";
//Following line breaks
this.performanceCounter.InstanceName = "Realtek RTL8139 Family PCI Fast Ethernet NIC - Virtual Machine Network Services Driver";
The problem is that the VS.NET 2003 hardcodes PerformanceCounter.InterfaceName in my application. I want to get this ethernet driver name at runtime. How do I do it?
Zishan
|
|
|
|
|
I am implementing a webservice that link to a database on the server machine, The operation on SELECT function work alright. However, operation such as INSERT, DELETE doesn't work at all. Could any one suggest why? I have tried various ways of INSERTing, I have tried using OleDbCommand as well as OleDbDataAdapter... but none of it works. The database I am using in MS Access though.
Thank you in advance
|
|
|
|
|
|
IIRC, when an Access db is opened, the default mode is read-only. SELECT will work fine, but any attempt to modify the data will fail, regardless of user permissions.
There are optional flags that can be set while creating the connection which override the defaults, though I don't remember where they're defined at the moment. Try MSDN - I was working with ADO when I bumped into this, so that might be a good section to start searching.
Boredom, Bull$^%&, Baggage, Bar - all start with 'B' Coincidence?
|
|
|
|
|
i want to make a dynamic form which creat its buttons like that for ex:
i have static 3 buttons : 1 , 2 and 3 at left and a panel at right
when i press button 1 it creat in the panel 3 butoons a , b and c
when i press button 2 it creat in the panel 2 buttons d and e
when i press button 3 it creat in the panel 5 buttons f , g, h , i and j
misho
|
|
|
|
|
|
yeah be sure that you included the created button on the panel by the following code
//here to add the class button to your panel
panel.Controls.Add(mybutton);
try this and tell me what happened ..
Miss With The Best And Die Like The Rest
|
|
|
|
|
Is wrapping every C++ classes in C# classes the only way to allow interopability between a C# application and a C++ DLL?
|
|
|
|
|
Hi,
I am using Visual Studio 2005 Beta 2 to create a 64bit application. The problem is that i have a com component that i need to reference from my c# application. I cannot add a reference to the com component. Basically, my 64 bit com object does not show up in the list of com components(it registers successfully) under the add reference tab and when i browse for the com component, trying to add it results in an error.
Has anyone run into this problem? Any suggestions?
Thanks.
|
|
|
|
|
I VC++ if you creaed a function to do a specific thing you first referenced it in the header file then added to the cpp file.
Example:
Header:
int myFunc();
CPP:
int CMyClassDLG::myFinc()
{
}
So in C# I created this dialog based app. I added a function to get all the nic listed on my machine. Called the function GetNics(). How do I call this?
When I try and call this in Main() is says something about
"C:\My Documents\Visual Studio Projects\MyNetwork\Form1.cs(111): An object reference is required for the nonstatic field, method, or property 'MyNetwork.Form1.GetNics()'"
So do I need to create a new class for each new function I want to do?
Can someone point me in the right direction?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Okay I think I may have found it. Can I not call any functions in the Main portion of my code? What I was doing was trying to load up a dropdown list when the form first loaded. I found out that by double clicking on the form created a function call Form1_Load in whick I could call my functions. So is this how I am supposed to do it?
Tom Wright
tawright915@yahoo.com
|
|
|
|