user3897675
user3897675

Reputation: 11

Displaying Computer Name at Application Startup

We would like to display the name of the computer being used on our application without having to click on a label or use of a messege box.

Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
    Label2.Text = My.Computer.Name
End Sub

The code above works but only when you click on the label.

How do we get it to just display as plan text.

Upvotes: 0

Views: 98

Answers (2)

user3910810
user3910810

Reputation: 234

Add a constructor to the window containing the label and assign the text in there.

Public Sub New()

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

    Label1.Text = My.Computer.Name
End Sub

Upvotes: 0

senthilkumar2185
senthilkumar2185

Reputation: 2568

  Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
        Label1.Text = My.Computer.Name
    End Sub

Upvotes: 1

Related Questions