VB.net标签不刷新(Me.Refresh())

时间:2015-04-30 13:57:35

标签: .net vb.net

我使用VB.net创建应用程序,之前从未使用过VB.net,所以我可能不知道自己在做什么。

我的问题是我的表单不会刷新标签,我尝试过使用Me.Refresh(),Me.Update(),我尝试在刷新之前使控件无效,我甚至尝试过应用程序。 DoEvents()(虽然我知道这不推荐)。

这里有两个片段,一个显示代码中变量变化的点,另一个显示变量显示的标签。

Private Sub Label1_Click(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label1.Click
    If e.Button = Windows.Forms.MouseButtons.Right Then
        ContextMenuStrip1.Show(CType(sender, Control), e.Location)
    End If
    Functionality.selectedTask = 0
    Me.Refresh()
End Sub

单击此(Label1)时,Label11应更新(Label1表示任务0)。

Me.Label11.Text = Convert.ToString(Functionality.selectedTask)

我正在测试以查看Label11是否更新(在最终程序中,这应该显示所选任务的描述)。它从15处的所选任务开始,但不会改变。我某些变量本身正在发生变化,但这种变化并未表现出来。

1 个答案:

答案 0 :(得分:0)

以下是如何使用Label事件更改Button.Click文字的简短示例。您应该能够将其粘贴到新的VB.NET Windows窗体应用程序中:

Option Strict On
Option Explicit On


Public Class Form1

    Private WithEvents newLabel As New System.Windows.Forms.Label
    Private WithEvents newButton As New System.Windows.Forms.Button

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        newLabel.Location = New Point(10, 10)
        newLabel.Text = "Orignial value"

        newButton.Location = New Point(10, 40)
        newButton.AutoSize = True
        newButton.Text = "Change the label"

        Me.Controls.Add(newLabel)
        Me.Controls.Add(newButton)

    End Sub


    Public Sub changeTheLabel(sender As Object, e As EventArgs) Handles newButton.Click
        Me.newLabel.Text = "Text Changed"
    End Sub
End Class