我试图加载一个表单时,一个按钮被单击。该表单应该显示一个标签的基础上,哪个按钮被单击。当我运行下面的代码一切正常工作,除了我通过按钮后,变量从最后一个按钮是唯一一个显示,无论我点击什么。
表格1
Public Class MainScreen
Public RebootServer As Integer = 0
Public StartServer As Integer = 0
Public StopServer As Integer = 0
Public CurrentServerInfo As Integer = 0
Private Sub RebootServerMenuItem_Click(sender As Object, e As EventArgs) Handles RebootServerMenuItem.Click
RebootServer = 1
CurrentConnectionForm.Show()
End Sub
Private Sub StartServerMenuItem_Click(sender As Object, e As EventArgs) Handles StartServerMenuItem.Click
StartServer = 1
CurrentConnectionForm.Show()
End Sub
Private Sub StopServerMenuItem_Click(sender As Object, e As EventArgs) Handles StopServerMenuItem.Click
StopServer = 1
CurrentConnectionForm.Show()
End Sub
Private Sub ConnectionInfoMenuItem_Click(sender As Object, e As EventArgs) Handles ConnectionInfoMenuItem.Click
CurrentServerInfo = 1
CurrentConnectionForm.Show()
End Sub
End Class
表格2
Public Class CurrentConnectionForm
Dim RebootServer As Integer = MainScreen.RebootServer
Dim StartServer As Integer = MainScreen.StartServer
Dim StopServer As Integer = MainScreen.StopServer
Dim CurrentServerInfo As Integer = MainScreen.CurrentServerInfo
Private Sub CurrentConnectionForm_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
If RebootServer = 1 Then
RebootServerLabel.Visible = True
StartServerLabel.Visible = False
StopServerLabel.Visible = False
ConnectionInfoLabel.Visible = False
End If
If StartServer = 1 Then
RebootServerLabel.Visible = False
StartServerLabel.Visible = True
StopServerLabel.Visible = False
ConnectionInfoLabel.Visible = False
End If
If StopServer = 1 Then
RebootServerLabel.Visible = False
StartServerLabel.Visible = False
StopServerLabel.Visible = True
ConnectionInfoLabel.Visible = False
End If
If CurrentServerInfo = 1 Then
RebootServerLabel.Visible = False
StartServerLabel.Visible = False
StopServerLabel.Visible = False
ConnectionInfoLabel.Visible = True
End If
End Sub
End Class
我尝试过将if语句更改为if/else if,并重新安排调用变量的时间。
当我在form 1上单击reboot server时,我希望form 2加载并显示reboot server的标签,start、stop和connection info也是如此。
1条答案
按热度按时间xoefb8l81#
创建一个
Enum
来保存四种不同的状态,然后声明一个该类型的Shared
变量:现在你的第二种形式变成了: