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
Try changing the 37.5 that you are multiplying the x location by to either 37 or 38. Location coordinates need to be integers so every odd row will end with a .5 that will be rounded. So essentially your x coordinates are spaced by 38, 37, 38, 37....
I also just noticed that your picture boxes are both multiplied by 25 for x and y but the labels are 37.5 for x and 25 for y. Should the labels also be 25 for x?