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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:51:09+00:00 2026-06-09T02:51:09+00:00

Just to know the best practice or code efficiency, I am having this piece

  • 0

Just to know the best practice or code efficiency, I am having this piece of code :

Just to note: I am using .Net Compact Framework.

protected override void OnPaint(PaintEventArgs e)
{
    if (BmpScreen == null)
    {
      BmpScreen = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
    }

    using (Graphics gBmpScreen = Graphics.FromImage(BmpScreen))
    {
         // some drawing using gBmpScreen
    }
    // finally
    e.Graphics.DrawImage(BmpScreen, 0, 0);
}

In this piece of code in the Paint method I am creating a Graphics object every time,

my question is it better to do it like this or is it better to create the graphics object only once in the beginning ?

  • 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-09T02:51:10+00:00Added an answer on June 9, 2026 at 2:51 am

    I’m not sure of the performance difference, but I’d recommend allocating and disposing of your back buffer Bitmap and Graphics objects in OnResize. I’ve found for most custom controls you can separate the actual work of updating the back buffer as close as possible to where the data changes occur, and simplify the the OnPaint to only blit the back buffer bitmap to the system’s Graphics. This worked well for a custom graph control I wrote, since the data did not change in response to user interaction. It was contained in a gesture scrolling control and greatly improved scrolling animation. But you could probably extend the pattern to handle more interactive controls by calling Update() in response to user interaction changes to force the OnPaint in the scope of your handler.

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

Sidebar

Related Questions

I know this is simple, I just can't recall the best way to do
I ask this partly because I want to know the best practice way of
Just want to know if publishing an application on Google play is allowed using
Just wanted to know if anyone is really using Objects and Collections in Oracle
I know it's 'technically' not the best practice to be hard coding strings; but
Not sure if this is considered best practice or if you should even do
We all know that global variables are anything but best practice. But there are
We just started using git for our production code, and we are running into
I'd like to know some best practice when designing c++ classes. To put it
DO YOU KNOW SOME MORE BEST PRACTICES FOR CANVAS?? Please add to this thread

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.