level 1
洒家不戒女色
楼主
初学vb.net,想显示点东西真心是不容易啊
如下程序,同样的事件,从Test过程里面产生就能正常显示Description,从SP_Datareceived事件里产生的就不能显示Description,但是语句能执行到TextBox1.Text=Text,
不知何因,请高手指点
串口类
Imports System.IO.Ports
Class SPXX
....Public Event CommandCompleted(ByVal Description As String) '定义指令完成事件
....Prvate WithEvents SP As New SerialPort '定义串口控件
....Private Sub Test() '一个非响应事件的过程
........RaiseEvent CommandCompleted(Description) '产生一个指令完成事件
....End Sub
....Private Sub SP_Datareceived(...........)Handles SP.Datareceived '处理串口的接收事件
........'一些数据处理
........RaiseEvent CommandCompleted(Description) '产生一个指令完成事件
....End Sub
End Class
窗口程序
Class Form1
....Public Shared WithEvents SPX As New SPXX
....Public Delegate Sub DlgShowText(ByVal Text As String)
....Public Sub ShowText(ByVal Text As String)
........TextBox1.Text=Text '程序都能执行到这里,从Test里发生的事件能显示,SP_Datareceived里发生的事件不能显示
....End Sub
....Private Shared Sub SPX_CommandCompleted(ByVal Description As String)Handles SPX.CommandCompleted
........Dim ST As Form1.DlgShowText(AdressOf Form1.ShowText)
........ST.Invoke(Description)
....End Sub
End Class
2014年11月24日 18点11分
1
如下程序,同样的事件,从Test过程里面产生就能正常显示Description,从SP_Datareceived事件里产生的就不能显示Description,但是语句能执行到TextBox1.Text=Text,
不知何因,请高手指点
串口类
Imports System.IO.Ports
Class SPXX
....Public Event CommandCompleted(ByVal Description As String) '定义指令完成事件
....Prvate WithEvents SP As New SerialPort '定义串口控件
....Private Sub Test() '一个非响应事件的过程
........RaiseEvent CommandCompleted(Description) '产生一个指令完成事件
....End Sub
....Private Sub SP_Datareceived(...........)Handles SP.Datareceived '处理串口的接收事件
........'一些数据处理
........RaiseEvent CommandCompleted(Description) '产生一个指令完成事件
....End Sub
End Class
窗口程序
Class Form1
....Public Shared WithEvents SPX As New SPXX
....Public Delegate Sub DlgShowText(ByVal Text As String)
....Public Sub ShowText(ByVal Text As String)
........TextBox1.Text=Text '程序都能执行到这里,从Test里发生的事件能显示,SP_Datareceived里发生的事件不能显示
....End Sub
....Private Shared Sub SPX_CommandCompleted(ByVal Description As String)Handles SPX.CommandCompleted
........Dim ST As Form1.DlgShowText(AdressOf Form1.ShowText)
........ST.Invoke(Description)
....End Sub
End Class