I have two forms. Form1 and Form2. SerialPort variable is declared in Form1.cs
public SerialPort COM = null;
public SerialPort GetCOMM
{
get { return COM; }
}
I need to access that variable from Form2. (Form1 creates Form2)
Have tried access to seriarialport these ways
Form1 f1 = new Form1();
int result = myfunction(f1.GETCOMM);
int result = myfunction(f1.COM);
and it’s not working. what I’m doing wrong?
I would personally create a Method on Form2 that takes a SerialPort as a Parameter, that way it does not have to have a reference to Form1. I would do something like this. Or you can create a Custom Constructor like jaminator commented for Form2 that Receives the SerialPort as a Parameter
Form1
Form2
Second Option with custom Constructor
Form1
Form2