?
Solved

dotnet graphics : how to draw a line with a DashPattern beginning with a space ?

Posted on 2010-03-30
2
Medium Priority
?
782 Views
Last Modified: 2013-12-17
Pen.DashPattern is "an array of real numbers that specifies the lengths of alternating dashes and spaces in dashed lines" (quoted fom MSDN). The first value in this array always corresponds to a dash. It's ok if the line begins with a dash but i need to draw lines beginning with a space (perhaps a bit strange but it can occur in some Autocad linestyles).

To do that, i added a 'virtual' dash at the beginning of the dashPattern, with a a very small value : for example DashPattern = {.00001, 10,5,10} : .00001 is an invisible dash, followed by a 10 pixels space, then a 5 pixels dash, and so on.
It works if the line is drawed with a one pixel width : the first dash is invisible; but if width > 1 pixel, the first dash is clearly visible.
I know that the effective dash length is = (value from DashPattern) x pen.Width , so i expected that for a 2 pixels width, (00001 x 2) would still give an invisible dot, but clearly on screen this dot has 2 pixels width.
0
Comment
Question by:JP_Goblet
2 Comments
 
LVL 12

Accepted Solution

by:
lazyberezovsky earned 500 total points
ID: 29098329
Use pen.DashOffset equal to first value of DashPattern.
0
 

Author Closing Comment

by:JP_Goblet
ID: 31708928
simple but effective solution ; writing dashOffset = dashPattern[0] didn't work at first time, the first dash was still visible. But after some thinking i guess that the very small value i used for the 1st dash (such as 0.000001F) was non-sense, since the values in DashPattern and DashOffset are floats and not doubles ; i don't know the precision of floats, but i presume that 0.000001F was rounded to 0 pixel (which was interpreted  somehow in GDI code as 1 pixel ?).

Anyway with your solution i don't need to use small values, since the the first dash will be 'eaten' by the dashOffset of same value; i tried for example dashOffset = dashPattern[0]  = 1, no problem.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question