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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:32:22+00:00 2026-06-03T08:32:22+00:00

I’ve got a few custom controls that are covered in images, and if they

  • 0

I’ve got a few custom controls that are covered in images, and if they get dragged off screen and back on, the image isn’t repainted properly. I’ve got on paint overriden for these various controls, and they seem to work fine, other than they don’t get drawn properly if dragged off screen on and on again. Anyone know why this might happen and/or a solution?

Edit: there seem to be issues with some of them even if the dialog is simply moved resized too fast, rather than just if it’s taken off screen. They start looking like they’ve been drawn on top of themselves. Which kind of makes sense, but I can’t figure out how to cure it.

Edit 2: These are custom buttons with fourstates (hover, click, normal, disabled), so I don’t think the container thing is the issue I don’t think..? The OnPaint code is:



private void CQPButton_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.Clear(BackColor);

    if (BackgroundImage != null)
        e.Graphics.DrawImage(BackgroundImage, e.ClipRectangle);

    if (Image != null)
    {
        RectangleF rect = new RectangleF();
        rect.X = (float)((e.ClipRectangle.Width - Image.Size.Width) / 2.0);
        rect.Y = (float)((e.ClipRectangle.Height - Image.Size.Height) / 2.0);
        rect.Width = Image.Width;
        rect.Height = Image.Height;
        e.Graphics.DrawImage(Image, rect);
    }

    if (Text != null)
    {
        SizeF size = e.Graphics.MeasureString(this.Text, this.Font);

        // Center the text inside the client area of the PictureButton.
        e.Graphics.DrawString(this.Text,
            this.Font,
            new SolidBrush(this.ForeColor),
            (this.ClientSize.Width - size.Width) / 2,
            (this.ClientSize.Height - size.Height) / 2);
    }

}

I’ve tried forcing repaint on various events, LocationChanged and Move to try and deal with the resize issue, ClientSizeChanged to try and deal with when they’re off screen, and nothing is sticking. I don’t know what I’m missing…

  • 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-03T08:32:23+00:00Added an answer on June 3, 2026 at 8:32 am

    I completely changed my answer after seeing the code snippet. It has a bug:

        RectangleF rect = new RectangleF();
        rect.X = (float)((e.ClipRectangle.Width - Image.Size.Width) / 2.0);
        rect.Y = (float)((e.ClipRectangle.Height - Image.Size.Height) / 2.0);
    

    Using e.ClipRectangle is incorrect here, it is a value that always changes, depending on what part of the control needs to be repainted. And yes, it changes most when you resize the control or drag it partially off the screen. You need to use the actual size of your control:

        rect.X = (float)((this.ClientSize.Width - Image.Size.Width) / 2.0);
        rect.Y = (float)((this.ClientSize.Height - Image.Size.Height) / 2.0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this
i got an object with contents of html markup in it, for example: string

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.