how to access serialPort1 in another form? [duplicate] - c#

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Best way to access a control on another form in WinForms?
how can I access serialPort1 which is in form2 in the MainForm(Form1) ?
I want to use the methods which is related to the serialPort1 control ?

Store your SerialPort object in a static location, like in your entrypoint Program class, then it's accessible from anywhere in your project during the life of your program.
Also consider giving your fields more descriptive names than "serialPort1".

Related

Modifying static variables from other scripts in Unity [duplicate]

This question already has answers here:
What is the use of static variable in C#? When to use it? Why can't I declare the static variable inside method?
(12 answers)
Closed 7 years ago.
Does anybody know how to modify a static variable from a different script in Unity?
Please, provide more information about how are you trying to do this...
If you need to change between mono behaviours, for example, you will need to get current instance of behaviour you like to change in a way like
myGameObjectInstance.GetComponent<MyBehaviourWithStatic>().myStatic = value;
but note that user2320445 answer is not wrong, it depends on your context. Be more specific on your question and we could provide better and precise answers

How to use array in two different forms? [duplicate]

This question already has answers here:
How to share data between forms?
(2 answers)
Closed 8 years ago.
I'm trying to use one array that I declared in one form, to plot a graph with zedgraph, in a different form.
How do I need to declare the array and where?
Short answer: Don't declare your array in the first form.
Declare it in a separate component/class/whatever instead, and let both forms access the array there. That way, the array should be independent of the forms, and both can use it.

C# class similar to Java Desktop class [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Open file with associated application
I want to open a file in it respective application, e.g. open function of windows.
Same thing can be done in java with the help of Desktop class where you pass the file name and the respective file is opened.
But no idea how to do in C#.
System.Diagnostics.Process.Start("filename.doc");

Accessing objects in several forms in C# [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Using and instance of a class on two forms
As I am pretty new to OOP - especially with Visual C# - I have a problem understanding the following:
A Windows Forms application has several forms. They all shall have access to a object Client (for communicating with a server) created in one of the forms. But how do I make exactly this object instance available in the other forms?
You can make the Client public static in the form parent form and access it from other forms. You have to make it thread safe if access synchronously.
Public will make it available to other forms where as make a single instance for all forms. To make it public static.
public static Client client.
To access it from other forms, assuming client is in Form1 and being accessed from other form.
Client client1 = Form1.client;

Singleton problem in c# [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
What is the correct way to create a single instance application?
What is a good pattern for using a Global Mutex in C#?
Suppose i have created an exe i want that exe must run only once ..how it is possible please give suggestion
If I understand your problem correctly this has nothing to do with having a singleton implementation. You simply need to check if your executable is currently running.
You can do this by calling Process.GetProcesses() or Process.GetProcessesByName(NameOfExecutable) and checking the return values.
Alternatively use a Mutex as suggested above by others.

Categories