0

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 ?

Community
  • 1
  • 1
  • There are *thousands* of "How to I access *foo* from another form" questions already. Just look at the right of this page. SerialPort is one of the few classes where it is almost always correct to declare the reference static. – Hans Passant Jan 24 '13 at 00:57

1 Answers1

0

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

Dai
  • 141,631
  • 28
  • 261
  • 374