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

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.

Related

I saw this in code to do with lists and I'm not sure what it does [duplicate]

This question already has answers here:
What does it mean when there is a comma inside an array declaration? e.g. float[,]
(4 answers)
Closed 2 years ago.
So I'm trying to learn from other peoples code and I saw this at the end of a list and could not find it anywhere I looked
List<IMyShipMergeBlock>[,] merges = new List<IMyShipMergeBlock>[3, 2];
What is [,] and [3,2] called and could you point me to where I could learn more about it thanks
its a multidimensional array of List<IMyShipMergeBlocks>
The [3,2] is the initialiser for the array
so imagine a 3x2 grid and in each square there is a space for a List<IMyShipMergeBlocks>
EDIT: And important to note: You would then need to initialise each list separately as with the above you have an array of nulls to start with

How to change the amount of elements in an array without creating a new one [duplicate]

This question already has answers here:
change array size
(15 answers)
Closed 3 years ago.
I want to create an array whose number of stored values increases by one every time a button is clicked. So I need a way to change the number of array elements during run-time.
You can use the Array.resize() method.
Documentation can be found here:
https://learn.microsoft.com/en-us/dotnet/api/system.array.resize?view=netframework-4.7.2
Array.Resize doesn't resize the array, it creates a new array with the specified size and copies all the elements from the old array to the newly created array and then replaces the old array with the new array however this would be suitable for you based on your question.

Control.ProductName in WPF [duplicate]

This question already has answers here:
Application.ProductName equivalent in WPF?
(7 answers)
Closed 8 years ago.
Is there something similar to the following property in WPF?
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.productname(v=vs.110).aspx
Thanks.
Not that I know of. But you can easily create this method yourself.
The actual code used by WinForms has several levels of fallback: it first look for an AssemblyProductAttribute on the assembly defining the control, then at the file version and finally falls back to the first part of the namespace.
You can copy that logic (or the parts that are relevant to you) directly from .net source code: http://referencesource.microsoft.com/#System.Windows.Forms/ndp/fx/src/winforms/Managed/System/WinForms/Control.cs#f7c944851a004a6e

Check for empty fields in form [duplicate]

This question already has answers here:
Find all controls in WPF Window by type
(17 answers)
Checking for unfilled fields with PHP
(3 answers)
Closed 9 years ago.
Is it possible to check a form for any empty text boxes rather than having to put a check on each individual text box with an if? Any help would be much appreciated.
I'm not that familiar with WPF, but you might try to get a list of the child-elements in a form, and for each, check if they are of type Textbox. If so, perform your validation.

how to access serialPort1 in another form? [duplicate]

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".

Categories