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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:47:48+00:00 2026-05-31T16:47:48+00:00

Currently I’m trying to do what I thought would be a simple task: Draw

  • 0

Currently I’m trying to do what I thought would be a simple task:

Draw an image onto the full area of a Panel control in Windows Forms. (Please ignore for the moment that I could use the BackgroundImage property)

The image to draw looks like this:

enter image description here

I.e. a yellow box with an 1 pixel blue frame around.

To draw, I’m using the Paint event of the Panel control:

private void panel1_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.DrawImage(Resources.MyImage, panel1.ClientRectangle);
}

This looks fine when initially displaying the form:

enter image description here

When resizing the form (and the docked panel, too), it either cuts the edges when being made smaller…

enter image description here

…or it draws artefacts, when being made larger:

enter image description here

I’m pretty sure that there is going on something rather simple and straight-forward but I really cannot understand the reason.

Since I’m ignoring the ClipRectangle and always draw everything, I thought the image would be scaled all the time.

My questions are:

  • What is the reason for the artefacts? (I love to understand this!)
  • What do I have to do in order to get rid of the artefacts? (beside calling Invalidate on each resize)

Update, SOLUTION:

Thanks to Ryan’s answer, I was able to find an acceptable solution. Basically I derived a class from Panel, did an override of OnPaintBackground and did not call the base method. Last, I added the following code to the constructor of my derived panel:

base.DoubleBuffered = true;

SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

UpdateStyles();
  • 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-31T16:47:49+00:00Added an answer on May 31, 2026 at 4:47 pm

    The reason for the artefacts is that the entire surface isn’t redrawn when the form is resized; only the necessary parts are. The generally best solution is what you don’t want to do, calling Invalidate on each resize. However, if this is in fact your situation, just use a PictureBox instead. If it’s not, you might consider overriding OnPaint in your form instead, and using this.SetStyle(ControlStyles.ResizeRedraw, true) to do this automatically.

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

Sidebar

Related Questions

Currently I'm learning C++ and I've been trying to create a simple image processing
Currently I am debugging the signing of an Android app. And this would be
Currently I’m trying to get the hang of a block copy with my current
Currently, my ListViews look like this: How can I achieve that Windows 7 native
Currently I am loading an image in to memory on a 2nd thread, and
Currently my WPF application imports a part like this [Import(typeof(ILedPanel)] public ILedPanel Panel {
Currently I have a simple setup where I maintain a list of bools corresponding
Currently, I'm developing an application for Android OS. I would like to know the
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
Currently my workflow with Emacs when I am coding in C or C++ involves

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.