Where Are My Labels Going?

E

eBob.com

Despite my bad cold and headache I should be able to correctly code
what I am trying to code below. Or should at least be able to
determine why such simple code does not work. I do have very similar
but more complicated code working in another project (thanks, I might
add, to several people here who have helped me).

The problem is that I never see the Labels. Using the debugger I can
see that the Text property of the Labels are correct. I could not
verify from the debugger that the Labels are actually being added to
the Panel Control, but I do not see how they could not be.


Dim chkbxSel(9) As CheckBox
Dim lbl(9) As Label

+ " Windows Form Designer generated code "

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

'populate panel
Dim yloc As Integer = 0
For i As Integer = 0 To 9
lbl(i) = New Label
yloc = i * (lbl(i).Height + 4)
chkbxSel(i) = New CheckBox
chkbxSel(i).Tag = i
chkbxSel(i).Location = New Point(0, yloc)
lbl(i).Width = 200
lbl(i).Text = "CheckBox " & i.ToString
lbl(i).Location = New Point(20, yloc)
Panel1.Controls.Add(chkbxSel(i)) ' < I see the
CheckBoxes
Panel1.Controls.Add(lbl(i)) ' < But I do not
see the Labels
Next
End Sub
 
G

Guest

Do you have the label backcolor set to transparent or the same color as your
form with border set to none?
 
G

Guest

Also, what is the height of your labels and checkbox's. Maybe the label is
behind the checkbox.
 
H

Herfried K. Wagner [MVP]

eBob.com said:
Despite my bad cold and headache I should be able to correctly code
what I am trying to code below. Or should at least be able to
determine why such simple code does not work. I do have very similar
but more complicated code working in another project (thanks, I might
add, to several people here who have helped me).

The problem is that I never see the Labels.

Maybe the problem is caused by an unpatched virus scanner. These symptoms
are typically caused by a McAfee VirusScan problem that NAI is aware of and
that can be fixed by installing a patch:

Patch 5 for McAfee VirusScan Enterprise 8.0i
<URL:https://knowledgemap.nai.com/phpclient/viewKDoc.aspx?url=kb/kb_kb38717.xml&docType=DOC_KnowledgeBase>
 
C

Cor Ligthert

Bob,

Your checkbox is hiding the label
\\\\
lbl(i).Location = New Point(110, yloc)
////

Without the perfect ones are we probably all making this kind of mistakes
and know that they consume the most time.

:)

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

Addendum:

I tested your code... The problem is that the checkboxes are so large that
the labels are hidden behind them. Change the 20 in 'lbl(i).Location = New
Point(20, yloc)' to a larger value. BTW: The checkbox has a 'Text'
property, so there is no need to add a caption by placing a label next to
it. Simply assign the caption string to its 'Text' property.
 
E

eBob.com

Thank you Herfried. I suspected something like that and tried different
values for location and size, but apparently didn't hit the right
combination. And thanks for making me aware of the Text property of
CheckBox. That will be very useful to me.

Bob
 
E

eBob.com

Thank you Cor. Poor debugging on my part. I should have eliminated the
CheckBoxes. Then I would have seen the Labels and realized that the problem
was some interaction between the two.

Thanks again, Bob

\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top