문제

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