I'm new to a C# and also to Visual Studio .NET, so please bear with me. I'm having a problem, despite reading this tutorial.
I have two forms in main form (Form1) I open a serial port for which data I want to get from the second form (Form2). In this form I select between COM1 and COM2 with a Radio button. So basically what I need to do Is pass string from Form2 to Form1 in to the method init_serial_port(string PORT) which is located in Form1. Also when I open a Form2 the right Radio button has to be set to true.
What I already coded:
Form1 Code:
public Form1()
{
InitializeComponent();
}
public void init_serial_port(string PORT)
{
if (!(serialPort1.IsOpen))
{
serialPort1.PortName = PORT;
serialPort1.BaudRate = 115200;
serialPort1.Parity = System.IO.Ports.Parity.None;
serialPort1.Handshake = System.IO.Ports.Handshake.None;
serialPort1.DataBits = 8;
serialPort1.StopBits = System.IO.Ports.StopBits.One;
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
serialPort1.Open();
}
}
private void selectCOMPortToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 COMS = new Form2();
COMS.ShowDialog();
COMS.Dispose();
}
Form2 Code:
public partial class Form2 : Form
{
string PORT = string.Empty;
public Form2()
{
InitializeComponent();
}
private void ok_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
PORT = "COM1";
}
else
{
PORT = "COM2";
}
Form1 glavni = new Form1(PORT);
this.Close();
}
}

New Topic/Question
Reply




MultiQuote





|