r/visualbasic • u/Thunor_SixHammers • May 19 '20
Unexpected label drifting
I have a grid based map plotting program. A bunch of pictures boxes that can be loaded with stuff on click. When it was small I would just drag out the PBs and labs (a b c, 1 2 3), but it's gotten so big that I'm now programmatically adding pbs and labels
Dim locx as int = 1
Dim locy as int = 1
For I as int = 0 to 24
Dim pb as new picture box
With pb
Pb.location = new point(25 * locx, 25 * locy)
Pb.height = 25
Pb.width = 25
End with
Me.gridpan.controls.add(pb)
If locx > 4 then
Locx =0
Locy +=1
Else if locx <5 then
Locx += 1
End if
NextThis works great. All the squares are flush next to eachother in a 5x5 grid. I add the same thing for the x labels
Locx = 1
Locy = 0
For I as int = 0 to 24
Dim titlex as new label
With titlex
Titlex.location = new point(37.5 * locx, 25 * locy)
Titlex.height = 25
Titlex.width = 25
End with
Me.gridpan.controls.add(titlex)
Locx += 1
NextThe first few labels look good, but as a whole they keep drifting further and further and further out of alignment with the picture boxes below them
5
Upvotes
1
u/redcorn89 May 19 '20
Do the labels get the same text in them? If not, setting the auto size property of the label to false. It’s true by default and will override the sizes you are assigning.
Also when you use with titlex you do not have to retype titlex in front of each line (On Mobile so hopefully formatting turns out correct)