1
In summary:
this object variable _serialPort of Form1
I want to use in the Print Class and in the other Form: Config_serial : Form
public partial class Form1 : Form
{
static SerialPort _serialPort; //instancio o obj no load_form
tried that:
private void ConfigurarToolStripMenuItem_Click(object sender, EventArgs e)
{
Config_Serial janela2 = new Config_Serial(this);
janela2.ShowDialog();
But I can’t use the variable here :
public Config_Serial(Form1 x)
{
InitializeComponent();
janela1 = x;
}
That’s pretty messed up "if I put public does not leave" What do you mean?
Form1
? where you are using the parameterfrm1
? If you receive aForm1
as a parameter, why does one need to instantiate another? It’s really hard to understand– Ricardo Pontual
"if I put public does not leave". What does this mean? If the code displays an error message, edit the question and show us the message. Another thing this fragment doesn’t say much, for example you have the line:
Form1 instanciaDoForm1; //crio um objeto do tipo FORM 1, que será usado dentro da classe
, and then makesinstanciaDoForm1._serial_serialPort.Write(result, 0,result.Length);
, from my point of viewinstanciaDoForm1
is null and last line will give error. Then we would need more code, not forgetting the error messages.– Augusto Vasques
is trying to create the method inside the class constructor, there is no way
– Lucas Miranda
@Lucas Miranda - Puts, this could be exactly what passed beaten. This confused because I tried to make a form, passing the form did not give, I tried to go through the method, but as it was with error nothing worked. What would be the most correct in this case, pass the form to the class or pass the instance variable of the serial port?
– Gilcecler Carneiro
@Gilceclercarneiro the correct is to edit the question by placing a more representative fragment of the situation and present the error messages so that the question can be reopened and our colleague can answer it properly.
– Augusto Vasques