编辑:
我想让我的问题更简单
检查代码
Public Class Form1
Dim v1 As Double
Dim v2 As Double
Dim v3 As Double
Private Sub Form1_Load(By Val sender As System.Object, By Val e As System.Eventuates) Handles My Base.Load
label1.text=v1
label2.text=v2
label3.text=v3
end sub
Private Sub Button1_Click(By Val sender As System.Object, ByVal e As System.Eventuates) Handles Button1.Click
v1=v1+10
v2=v2+20
v3=v3+30
End Sub
end class
我想在按钮时直接在表单中更改标签 如何在按钮子中没有加载表单的情况下执行此操作?
答案 0 :(得分:0)
我不太了解你的问题但是调用Form1_Load很奇怪并且将label2设置为未初始化的值也很奇怪。我建议你把所有的显示逻辑放在一个方法中。
Private Sub DisplayScrollValue(ByVal scrollValue As Double)
Label1.Text = scrollValue
label2.text = scrollValue
End Sub
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
DisplayScrollValue((VScrollBar1.Value * -1 / 10).ToString())
End Sub
Private Sub Form11_Load(By Val sender As System.Object, By Val e As System.Eventuates) Handles My Base.Load
DisplayScrollValue(0)
end sub
我注意到你的编辑和解决方案与我写的非常相似。只需要一个设置标签的方法,并在需要更新时调用它。
Public Class Form1
Dim v1 As Double
Dim v2 As Double
Dim v3 As Double
Private Sub UpdateLabels()
label1.text=v1
label2.text=v2
label3.text=v3
End Sub
Private Sub Form1_Load(By Val sender As System.Object, By Val e As System.Eventuates) Handles My Base.Load
UpdateLabels()
end sub
Private Sub Button1_Click(By Val sender As System.Object, ByVal e As System.Eventuates) Handles Button1.Click
UpdateLabels()
End Sub
end class