打开表单,显示系统信息

时间:2014-12-01 14:23:43

标签: vb.net winforms visual-studio

我希望能够打开我的表单并自动显示此信息,而无需单击按钮。我该怎么做呢?这就是我现在所拥有的,我只是想让它自动化。我不是程序员。我正在使用Visual Basic 2010 Windows窗体应用程序。

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByBal e As System.EventArgs) Handles Button1.Click

    Label1.Text = My.Computer.Info.OSFullName
    Label2.Text = SystemInformation.UserName
    If System.Environment.Is64BitOperatingSystem = True Then
        Label3.Text = ("64-Bit Operating System")
    Else
        Label3.Text = ("32-Bit Operating System")

    End If

  End Sub

End Class

1 个答案:

答案 0 :(得分:0)

正如一些人已经提到过的,你可以在班级的FormLoadEvent或构造函数LoadEvent中执行此操作...

这里是构造函数

 Public Sub New()
  ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

  Label1.Text = My.Computer.Info.OSFullName
  Label2.Text = SystemInformation.UserName
  If System.Environment.Is64BitOperatingSystem = True Then
    Label3.Text = ("64-Bit Operating System")
  Else
    Label3.Text = ("32-Bit Operating System")
  End If
End Sub

您的onload事件

 Private Sub Me_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

  Label1.Text = My.Computer.Info.OSFullName
  Label2.Text = SystemInformation.UserName
  If System.Environment.Is64BitOperatingSystem = True Then
    Label3.Text = ("64-Bit Operating System")
  Else
    Label3.Text = ("32-Bit Operating System")
  End If   

 End Sub