Graphics.Drawline one pixel short on device?

M

Minerva Jones

I've got a UserControl derived control which uses e.Graphics.Drawline
to draw a few lines in OnPaint. I've noticed that the lines, whether
horizontal or vertical are always one pixel longer on the device or
the emulator, to how they appear in Visual Studio at design time. By
my maths, VS is getting it right, the device is actually one pixel
more.

So if I have:

e.Graphics.DrawLine(p, 0, 0, 0, 10);

In Visual Studio the line will be 10 pixels high. In both the emulator
and on a device, it will be 11 pixels high (and thus finish a pixel
lower).

Is there some scaling factor I'm not taking into account? The DpiX and
DpiY are 96 in all cases.
 
M

Minerva Jones

In reply to Minerva Jones ([email protected]) who wrote this in
(e-mail address removed), I, Marvo, say :


It should be 11 pixels, as 0.10 is 11 pixels away from 0.0

if you draw from 0.0 to 0.0 the line will be exactly one pixel long, you
can't have 0 as a line length.

Ah, ok yes, I see that, thanks. I think I've got myself confused with
all the experiments I've been doing. The subject title I used
conflicted with the body of the message!

So there's still a problem with the device-desktop disparity. It would
seem that the desktop draws 0-10 *not* inclusive of the last pixel,
whereas the device does. I've ruled out scaling since it's always one
pixel shorter regardless of whether the line is 3 pixels or 300
pixels. Doesn't this cause issues for anyone else? Do you just make
sure your controls are correct for the device and ignore their odd
appearance in the designer? Or do I really need to switch on whether
I'm design or runtime and adjust everything by a pixel?!
 
U

Uncle Marvo

In reply to Minerva Jones ([email protected]) who wrote this in
(e-mail address removed), I, Marvo, say :
Ah, ok yes, I see that, thanks. I think I've got myself confused with
all the experiments I've been doing. The subject title I used
conflicted with the body of the message!

So there's still a problem with the device-desktop disparity. It would
seem that the desktop draws 0-10 *not* inclusive of the last pixel,
whereas the device does. I've ruled out scaling since it's always one
pixel shorter regardless of whether the line is 3 pixels or 300
pixels. Doesn't this cause issues for anyone else? Do you just make
sure your controls are correct for the device and ignore their odd
appearance in the designer? Or do I really need to switch on whether
I'm design or runtime and adjust everything by a pixel?!

Surely you can't think that Microsoft could possibly make a mistake :)

I am confused as to why you'd want to do a designtime line and then draw one
programatically though. Which version of VS are you using? How are you
drawing the line? Is it on a web page or a dialog?

So many questions.
 

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