質問

The code that I am using below does not work, I am fairly experienced with vb.net and have never run into this issue before, the label simply doesn't appear when the form loads (the code is inside the Load event handler procedure).

Dim currentUserLabel As New Label 
    With {.Text = "Logged in as: " + firstName + " " + _ lastName, 
    .Location = New Point(5, 3), .Font = New Font("Microsoft Sans Serif", 
    18, FontStyle.Bold)}
MenuTab.Controls.Add(currentUserLabel)
currentUserLabel.AutoSize = True
currentUserLabel.BringToFront()
MenuTab.Refresh()
役に立ちましたか?

解決 2

Finally sorted it, I invalidated the label when the form loaded, then created an event method which handles the invalidation of the label. I used the code that I had already been trying in this method and it worked. No idea why it wouldn't just load the label text when the form loaded :P. VB is stupid sometimes...

他のヒント

You cannot add controls to the TabControl, just it's pages.

 Dim currentUserLabel As New Label With {.Text = "Logged in as: " + firstName + " " + _ lastName,
 .Location = New Point(5, 3), .Font = New Font("Microsoft Sans Serif", 18, FontStyle.Bold)}
 MenuTab.TabPages(0).Controls.Add(currentUserLabel)
 currentUserLabel.AutoSize = True
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top