如何在Button2_Click中使用Button1_Click串行端口

如何在Button2_Click中使用Button1_Click串行端口

问题描述:

所有人都好,

我正在开发一个vb应用程序.在那我在Button1_Click事件中使用Serialport.但是现在我想在Button2_Click事件中使用相同的串行端口.....
请帮助我

感谢ADV .....

Hai to all,

I am developing one vb application . In that i am using Serialport in Button1_Click Event. But now i want to use the same serialport in Button2_Click event.....
Plz help me

Thanks in ADV.....

将SerialPort变量的声明移到Button1事件处理程序之外.如果它是一个类级别(即在表单内),则相同形式的两个按钮处理程序都可以访问它.
Move the declaration of the SerialPort Variable outside the Button1 event handler. If it is a class level (i.e. within the form) then both button handlers in the same form can access it.