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

  • Home
  • SEARCH
  • 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 184017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:13:05+00:00 2026-05-11T15:13:05+00:00

I’m experiencing an issue with GDI+ while custom painting dashed rectangles. The vertical portion

  • 0

I’m experiencing an issue with GDI+ while custom painting dashed rectangles.

The vertical portion of dashed rectangles appear as solid, continuous lines when the window size is increased or when scrolling up/down. Moving the mouse faster results in fewer and fewer solid sections. Curiously the horizontal lines do not exhibit this behaviour and appear as expected.

So far two non-optimal solutions have been to set ResizeRedraw = true or to call Invalidate() during OnResize() and OnScroll(). I’d of course like to avoid this as what I am really drawing is more complex and these slow calls destroy the fluid experience. I’ve also tried invalidating only the newly shown area to no avail – only a full Invalidate seems to work.

Any pointers on how to work this out?

Demo code:

using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms;  public class Form1 : Form {     static void Main()     {         Application.Run(new Form1());     }      public Form1()     {         this.ClientSize = new System.Drawing.Size(472, 349);          DoubleBuffered = true;         //ResizeRedraw = true;     }      protected override void OnPaint(PaintEventArgs e)     {         base.OnPaint(e);          int dimensions = 70;          using ( Pen pen = new Pen(Color.Gray) )         {             pen.DashStyle = DashStyle.Dash;              for ( int x = 0; x < 20; ++x )             {                 for ( int y = 0; y < 20; ++y )                 {                     Rectangle rect = new Rectangle(x * dimensions, y * dimensions, dimensions, dimensions);                      e.Graphics.DrawRectangle(pen, rect);                 }             }         }     } } 
  • 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. 2026-05-11T15:13:06+00:00Added an answer on May 11, 2026 at 3:13 pm

    I think there are two problems: there appears to be an area at the edge of the window where rectangles aren’t drawn correctly; and you’re drawing the rectangles over each other, so the dashing won’t work properly.

    Replace your OnPaint loop with the following:

       for (int y = 0; y < Height; y += dimensions)    {        e.Graphics.DrawLine(pen, 0, y, Width, y);    }    for (int x = 0; x < Width; x += dimensions)    {        e.Graphics.DrawLine(pen, x, 0, x, Height);    } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you actually saving the state of your panel (the… May 11, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Here's a tutorial on just how to do that: http://www.youcanlearnseries.com/Programming%20Tips/CSharp/LDAPReader.aspx May 11, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Nope, not bad form at all. After all, at least… May 11, 2026 at 5:39 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.