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