繁体   English   中英

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

[英]VB.net Labels not refreshing (Me.Refresh() )

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

我的问题是我的表单无法刷新标签,我尝试过使用Me.Refresh(),Me.Update(),在刷新之前尝试使控件无效,甚至尝试过Application.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开始,但不会更改。 我确定变量本身正在变化,但是这种变化只是没有表现出来。

这是一个简短的示例,说明如何使用Button.Click事件更改Label的文本。 您应该能够将其复制粘贴到新的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM