Delegate的问题

youyiyang 2016-03-16 09:48:46

Imports System.Threading
Imports System.Windows.Forms

Public Class Form1
Dim t As Thread
Public Delegate Sub SetText1(ByVal [text] As String)

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
t = New Thread(New ThreadStart(AddressOf Me.SetText1))
t.Start()
End Sub
Public Sub SetText1(ByVal [text] As String)

' InvokeRequired required compares the thread ID of the
' calling thread to the thread ID of the creating thread.
' If these threads are different, it returns true.
If Me.TextBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.TextBox1.Text = [text]
End If
End Sub
End Class


这段代码报2个错,为啥?
1. “SetText1是ThreadExample1.Form1中的类型,不能用作表达式”
2. “SetText1已声明为此class中的'Delegate Sub SetText1(text As String)'”
...全文
164 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
报错很明显。读不懂错误提示,是因为对于基本概念实在是无法专注、不真正去学。
楚狂歌 2016-03-26
  • 打赏
  • 举报
回复
Me.SetText1。。。。。。。同一个类不起作用
轻鸿万里 2016-03-18
  • 打赏
  • 举报
回复
支持一楼,方法重复了
yangyi_2009 2016-03-16
  • 打赏
  • 举报
回复
委托名是 SetText1,方法名也是 SetText1,所以报错。 把其中之一名称换掉。

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧