473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How do you draw a line on a canvas in WPF that is 1 pixel thick?

complete
How do you draw a line on a canvas in WPF that is 1 pixel thick?

This is the method I am using for drawing a line on a canvas in WPF that uses the line class set to 1 pixel thick but it actually draws a line that is two pixels thick:

Expand|Select|Wrap|Line Numbers
  1.             Line myLine = new Line();
  2.  
  3.             myLine.Stroke = System.Windows.Media.Brushes.Black;
  4.  
  5.             myLine.X1 = 100;
  6.             myLine.X2 = 140;  
  7.             myLine.Y1 = 200;
  8.             myLine.Y2 = 200;
  9.  
  10.             myLine.StrokeThickness = 1;
  11.  
  12.             graphSurface.Children.Add(myLine);
  13.  
Microsoft might have decided to set a standard for line thickness and the minimum is 2 pixels thick when you set the strockThickness to 1, but when you already have rectangles drawn in XAML and even error fonts using WingDings, it is an obvious miss-match. How do you draw a line that is truly 1 pixel thick?


I tried:
myLine.StrokeThickness = 0.5;
but that only makes the line burry.

Is there some sort of setting I need to make in the grid instead?
May 21 '10 #1

✓ answered by complete

It had to do with screen resolution.
I found "Snap To Pixel" commnds that worked

2 5441
ThatThatGuy
449 Expert 256MB
@complete
I don't see any difference ... that 1px is really one pixel
May 21 '10 #2
It had to do with screen resolution.
I found "Snap To Pixel" commnds that worked
May 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Rolf Brauser | last post by:
Hello, is it possible to draw a one pixel line around every cell in a table? with "border: 1px solid; " just the outer tableborder ist concerned ? thanks for any help rolf
1
by: John | last post by:
How can I draw single 1x1 pixel "dot" in window? Not a line, I really mean "dot".
1
by: Pat Keel | last post by:
Hi there, I'm looking for a solution to draw a one pixel sized point to a graphics control. E.g. DrawLine(10,10, 11,11) draws 2 pixels, DrawLine(10,10, 10,10) has no effect. How to do? Thanks...
4
by: thomasp | last post by:
I found the following code on MSDN to draw a line in VB2005. Public Sub DrawLinePoint(ByVal e As PaintEventArgs) ' Create pen. Dim blackPen As New Pen(Color.Black, 3) ' Create points that...
1
by: balakrishnan.dinesh | last post by:
Hi frnds, Im creating function to plot line graph in javascript . I have marked the points in graph. but what i need to do is, i want to draw the line between those marked point, but i dont...
18
by: sadegh | last post by:
I am using VC++6. I want to draw some simple shapes (e.g. line, circle, pixel) on a dialog box. How can I do this? Thanks a lot
10
by: marss | last post by:
<hr style="height:1px"/does not fit because although a line looks like it has 1 pixel with but there are empty spaces above and below line. It can be seen if place two HR elements beside. <hr...
2
by: cty0000 | last post by:
I need to draw only 1 pixel but I can not found out the way... I tried to use like following in some function (point1 is Point instance) Graphics gB = Graphics.FromImage(gBmp); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.