使用VB.NET Windowsforms,我需要从form1中显示的“ usercontrol”中更新“ form1”上的标签。
使用以下命令将用户控件添加到表单中:
Dim userControl As New Settings_SQLite_Gen_UserControl
Me.Settings_Panel.Controls.Add(userControl)
userControl.Location = New System.Drawing.Point(0, 0)
我在Form1上尝试过:
Private Delegate Sub UpdateLabelDel(ByVal txt As String)
Public Sub UpdateLabel(ByVal txt As String)
If Me.InvokeRequired Then
Invoke(New UpdateLabelDel(AddressOf UpdateLabel), txt)
Else
Label1.Text = txt
End If
End Sub
在用户控件中:
Private Sub Reset_btn_Click(sender As Object, e As EventArgs) Handles Reset_btn.Click
Dim SomeText As String = "Some text to change the label to"
UpdateLabel(SomeText)
End Sub
我在'Sub UpdateLabel'中放置了一个断点,它确实被调用,但是标签未更新。
谢谢你。