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 5929521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:25:57+00:00 2026-05-22T14:25:57+00:00

private void UserControl1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawEllipse(Pens.Black, new Rectangle(-200, -500, this.Width + 400,

  • 0
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.DrawEllipse(Pens.Black, new Rectangle(-200, -500, this.Width + 400, this.Height + 420));
}

Paste the above code into a usercontrol. Drop the usercontrol onto a form and anchor it to all 4 points.

In the designer (Under Visual Studio 2010) it renders perfectly (even as you resize). Run it and try and resize the form and the ellipse becomes skewed.

Here are two examples both after resizes the first while running, the second in the designer.

Running After Resize
Designer After Resize

Obviously the behavior in the designer can’t always be assumed to be the same (Although it would be nice) but my understanding is that the code above is completely legal. Am I wrong?

  • 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-05-22T14:25:57+00:00Added an answer on May 22, 2026 at 2:25 pm

    Stecya has posted the “fix”, but omitted an explanation detailing why that works or why you’re seeing a discrepancy between the behavior in the designer and in the running application. In my mind, that makes the answer only minimally useful, so I thought I’d weigh in with an attempt at an explanation.

    You already know that calling the Invalidate method is the solution. What this does is tell Windows that the entire surface area of the control needs to be redrawn the next time the window gets painted. Simple enough, but why don’t you have to do this in the designer?

    The answer lies in the fact that you’re running the program with the Windows Aero theme enabled. Aero uses an entirely new window manager called the Desktop Window Manager (or DWM for short) based on composition. Each window is double-buffered, meaning that its graphics are rendered off-screen into a temporary bitmap, and only then blitted to the screen. This allows all sorts of cool effects and fancy transitions that users seem to like nowadays.

    But, of course, it means that the sections that have already been drawn aren’t erased and redrawn unless you explicitly instruct Windows that it needs to do so. That’s not a problem for the form inside the designer, because there, Aero’s DWM composition is not enabled. When the window gets resized, it is automatically redrawn, and your swoosh looks smooth and correct.

    Outside of the designer, with Aero composition enabled, only the newly-exposed portions of your control are redrawn (the rest are still there in the buffer), so the shape is wrong. Part of the old shape is still there, and part of the new shape was just drawn in. Calling Invalidate tells Windows “the graphic surface of this control has changed; forget everything you thought you knew about it and redraw it from scratch next time”. So Windows dutifully obeys, discarding that portion from its off-screen buffer and redraws it in from scratch, producing a correctly-rendered, nicely-smoothed path.

    You can effect the same change in another somewhat more elegant way: Tell the control that it needs to redraw itself every time that it is resized. Insert the following code into the control’s constructor method:

    public MyUserControl()
    {
        // Force the control to redraw itself each time it is resized
        this.SetStyle(ControlStyles.ResizeRedraw);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

. private void Form1_Load(object sender, EventArgs e) { List<CaclulatedData> tests = new List<CaclulatedData> {
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { if (MessageBox.Show(this,
Code example: private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if(some condition) { comboBox.Text =
private void activateRecords(long[] stuff) { ... api.activateRecords(Arrays.asList(specIdsToActivate)); } Shouldn't this call to Arrays.asList return
private void EnsureCurrentlyValid() { //I'm valid if IDataErrorInfo.this[] returns null for every property var
private void validateXML(DOMSource source) throws Exception { URL schemaFile = new URL(http://www.csc.liv.ac.uk/~valli/modules.xsd); SchemaFactory schemaFactory
private void save(Rectangle src, Rectangle dest, string fName, int width, int height, Bitmap file)
private void BindCountry() { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(countries.xml)); foreach (XmlNode node in
I have this code private void writeReport(IReport report, string reportName) { string reportString =
private void StringAction(string aString) // method to be called { return; } private void

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.