-
I'm drawing lines and shapes in a picturebox. Why can't I position those exactly on a desired spot.
For example: I want to draw a circle and a vertical line just over the middle of the circle. I'm using the correct values relative to each other (Line.X = Circle.Left+0.5*Circle.width) to position both figures, but the result is a line which is just a bit off the middle, why?
By the way, I'm using a User Scalemode, is that the problem?
-
You should position them relative to the PictureBox. Also, remember to subtract half the width and height so it's even on both sides.
Code:
'Position the Circle
MyCircle.Move (Picture1.ScaleWidth / 2) - (MyCircle.Width / 2), (Picture1.ScaleHeight / 2) - (MyCircle.Width / 2)
'Position the Line
With MyLine
.X1 = Picture1.ScaleWidth / 2
.X2 = Picture1.ScaleWidth / 2
.Y1 = 0
.Y2 = Picture1.ScaleHeight
End With
-
Thanks Meg'
but I'm using all the correct(hopefully(:-)) values, the problem comes when I'm using small values of scale For example a circle of with a radius of 1 (width and height =2) is not printed correctly around a cross at the position X=circle.left+circle.width/2 and y=circle.top-Circle.height/2.
What kind of variables are X and Y? Integer, Single, Long ??
-
what is you ScaleMode-setting? asuming it is twips, try changing it to pixels and see if that helps.
best regards
Sascha
-
I'm using the "User ScaleMode", and I need it.
I'm working on a chart (Lat/Long conversion) and on a measurement tool with changing scales ( Scalewidth from 5 to 1000 changed during runtime).
So I would like to stay with that, otherwise the recalculations will drive me nuts.
-
All coordinates in both circle and line are single.
It's a floating point which could cause malcalculations with some extreme values, but i wouldn't suggest that's the possible problem
-
lines and shapes
I have looked into this quickly just now, and I can tell that if you make a cross inside the circle instead it pinpoints the centre prefectly. If you make a "plus" is it out by a small % EVERY time no matter how big or small the circle is.
I would hazard a guess and say that this is due to something very basic we are missing OR something very complex about pixel density and the fact that a vertical line has to consist of pixels directly above/below each other whereas a diagonal line "skips" pixles givin the illusion of being accurate.
Both of my methods pinpoint the same place mathematically, however they are definitely rendered differently.
Can you chance to a X in your circle without major problems?
Regards
Paul Lewis
-
I'm sure youre right Paul, and I think the problem lays in th shape control, so I guess it wouldn't be easier but a lot more accurate with drawing lines and shapes directly on the form, and also it's not consuming any resoruces at all
-
lines/shapes/controls
I was actually using lines and circles rather than shapes.
I also tried shapes and these were no better. On my monitor, vertical lines always appear thicker than horizontal or diagonal lines. I am sure a techie will know why :)
Cheers
Paul Lewis
-
Thank's
I think the problem is as Paul has discribed it, since each line must have a dimension it can't be "exactly" on the spot.
For me that's OK, 'cause it does not affect my application in general. It just looks a bit strange to see a cross in a circle that should be in the middle and it isn't if your in the wrong scale (the cross has a size independant of scale, the circle goes with the scale). Try it with a cross that fills a small circle.
Anyway thanks, I continue on other problemspot of my app.