Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:23:17+00:00 2026-06-17T20:23:17+00:00

Thes screenshots, taken from my MFC application, show lines 2 that should be parallel.

  • 0

Thes screenshots, taken from my MFC application, show lines 2 that should be parallel.
2 dashed, parallel lines 2 parallel lines, one solid the other dashed

The Lines are drawn using Gdiplus::Graphics::Drawline().

A minor issue is that the dashed lines are not straigt but broken. You notice it but it’s not a big deal…

The real problem is that it’s not consistent and lines drawn with Gdiplus::DashStyleSolid are really straight.

Is this a bug in GDI+? Is there a workaround?

Update 1

I tried making a minimal example but I’m struggling to reproduce it…
It may have something to do with very large coordinate values and little difference between their coordinates.
These are some example line coordinates:

Line 1: PointF(2.21866e+006, 1.40198e+006), PointF(2.21732e+006, 1.40111e+006)
Line 2: PointF(2.21866e+006, 1.40198e+006), PointF(2.21732e+006, 1.40112e+006)

I noticed that the start points are identical but this may be caused by rounding in the debug output…

Update 2

I could reproduce it now:
The sample application was generated as SDI project and the view class inherits CScrollView (code and screenshot below).
The "broken line" effect also appears to be related to the pen’s thickness. The line runs a bit different with varying thickness but I did not find a value that results in parallel lines all the time.

Vincent Porvik suggests in a comment that this might be the result of rounding errors, since Gdiplus::REAL is defined as float.
I believe this is the case as well…

Do I have any options other than somehow using smaller coordinate values here?

Code and Screenshot

These functions were added/modified (in addition to the GDI+ initialization code):

void CgdiplusLinesView::OnDraw(CDC* pDC)
{
    CgdiplusLinesDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    pDC->SetBkMode(TRANSPARENT);

    using namespace Gdiplus;
    Graphics g(pDC->m_hDC);
    g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);

    Pen solidPen(Color(0,0,0), 2.f);
    Pen dashedPen(Color(0,0,0), 2.f);
    dashedPen.SetDashStyle(DashStyleDash);

    g.DrawLine(&dashedPen, PointF(4438749.500000, 2805806.500000), PointF(4434280.500000, 2802106.500000));
    g.DrawLine(&solidPen,  PointF(4438746.500000, 2805809.500000), PointF(4434277.500000, 2802109.500000));
}

void CgdiplusLinesView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
    pDC->SetMapMode(MM_ISOTROPIC);

    const int mapSizePixels = 8388608;
    pDC->SetWindowExt(mapSizePixels, mapSizePixels);
    pDC->SetViewportExt(mapSizePixels, mapSizePixels);
    pDC->SetWindowOrg(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));

    //__super::OnPrepareDC(pDC, pInfo);
}

void CgdiplusLinesView::OnInitialUpdate()
{
    CScrollView::OnInitialUpdate();

    SetScrollSizes(MM_TEXT, CSize(8388608, 8388608), CSize(1361, 1054));
    SetScrollPos(SB_HORZ, 4434897.5);
    SetScrollPos(SB_VERT, 2802645.);
}

crossing lines

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:23:18+00:00Added an answer on June 17, 2026 at 8:23 pm

    I don’t think it has to do with dashed vs solid, but with float precision. Your coordinates seem to be geographic coordinates. The usual good practice has been to store all coordinates as doubles, and when you need to work with a lower precision library, offset all coordinates yourself before passing them to the graphics functions.

    The correct way to do that is to choose a reference point that is close to the points in your dataset (first coordinate you find is ok) and then substract its coordinates to all other points. This keeps the numerical values near 0.0 that is where floats have higher resolution density.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have JSF web application that generates XLS file and gives user link to
I have two tables Table1 and Table2. I compared thes tables using the query
Using Oracle 11 I'm wanting to pull data from a table, and add a
I want to know the best way to do that: using (var backgroundWorker =
I started using VS2010 and C# and the { s are weird. If I
I'm Downloading stock prices from Yahoo for the S&P500, which has volume too big
After cloning an SVN repository using git-svn with the -s option ( git svn
I am using NHunspell for checking spelling.I added NHunspell.dll as a reference to my
I'm trying to create a cpan module that integrates Text::Haml into Template Toolkit. I
I'm trying to use the OleDb CSV parser to load some data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.