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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:53:46+00:00 2026-06-16T16:53:46+00:00

I am currently using the paint event on a form to draw an image

  • 0

I am currently using the paint event on a form to draw an image onto the screen. (Think a background image) and some rectangles on top of this image.

 private void MainWindow_Paint(object sender, PaintEventArgs e)
 {
    e.Graphics.Clear(Color.CornflowerBlue);
    e.Graphics.DrawImage(Image.FromFile(m_Directory + @"\Images\" + BackgroundText), m_Screen);
    e.Graphics.FillRectangle(BGBrush, new Rectangle(X, Y, Width, Height));
    e.Graphics.DrawString(Text, Settings.TextFont, Other.Settings.TextBrush, new Rectangle(X, Y + 2, Width, Height));
 }

The page is being repainted very often (almost on every mouse move event) and is causing huge amounts of memory to be used. Getting to 1,500,000k before it stops drawing to the form and displays the white background with red cross on the picture for a failed paint.

I am at a slight loss as to how it is running off so badly. I am new to drawing with the paint event so any help will be much appreciated!

  • 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-16T16:53:47+00:00Added an answer on June 16, 2026 at 4:53 pm

    Image is IDisposable, so you should execute the DrawImage call within a “using” block, to ensure the Image is disposed.

    But most importantly, I would reconsider doing heavy IO operations in a Paint event. Possibly have the images loaded ahead of time, to have the Paint event only worry about drawing. You are currently loading the same image hundreds of times.

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

Sidebar

Related Questions

I mean using paint event but not to draw on the pictureBox1.Image and not
I am currently using Google API to point the position on Google map. this
I'm considering using memcached (at some point) in my application i'm currently developing. Eventually,
Currently using MySQL version 5.1.6 This is my first real world build and so
I currently using android NDK to write some native code in C. I have
I am currently using the code in main.cs to draw out the GUI instead
I'm currently trying to make a register form using mongoDB and nodeJS - I've
I am doing some image scaling using GDI+ (C#), and have noticed a problem
Currently my main form has a ton of event handlers because there are a
I am currently creating a point and click app for the iphone using cocos2d.

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.