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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:14:32+00:00 2026-05-14T06:14:32+00:00

I am trying to create this simple application in c#: when the user double

  • 0

I am trying to create this simple application in c#: when the user double clicks on specific location in the form, a little circle will be drawn. By one click, if the current location is marked by a circle – the circle will be removed.

I am trying to do this by simply register the MouseDoubleClick and MouseClick events, and to draw the circle from a .bmp file the following way:

private void MouseDoubleClick (object sender, MouseEventArgs e)
{
    Graphics g = this.CreateGraphics();
    Bitmap myImage = (Bitmap)Bitmap.FromFile("Circle.bmp");
    g.DrawImage(myImage, e.X, e.Y);
}

My problem is that I dont know how to make the circle unvisible when the user clicks its location: I know how to check if the selected location contains a circle (by managing a list of all the locations containig circles…), but I dont know how exactly to delete it.

Another question: should I call the method this.CreateGraphics() everytime the user double-clicks a location, as I wrote in my code snippet, or should I call it once on initialization?

  • 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-14T06:14:32+00:00Added an answer on May 14, 2026 at 6:14 am

    My personal preference is to put my images in instances of the Picturebox class. Reason being, I can simply call each Picturebox’s Hide() function (or set ‘Visible` to false).

    What you’re doing is drawing directly onto the window’s client area, which technically isn’t wrong but normally should be done in the form’s Paint handler. If at some point you decide you don’t want your circle to be visible anymore, you can call the form’s Invalidate() method which triggers the Paint event. There, you explicitly do not draw your circle, and so to the user, the circle disappears.

    The nice thing about a Picturebox is that it’s persistent – you put your image into it and optionally draw on that image, but you only need to draw once. If you use the Paint handler technique, your drawing code gets called each time the form needs to redraw itself.

    Edit:

    Here’s some code that illustrates my Paint handler information:

    private void Form_Paint(object sender, PaintEventArgs e)
    {
       e.Graphics.Clear();  // clear any and all circles being drawn
    
       if (CircleIsVisible)
       {
         e.Graphics.DrawEllipse( ... ); // OR, DrawImage( ) as in your example
       }
    }
    
    private void MouseDoubleClick (object sender, MouseEventArgs e)
    {
       CircleIsVisible = true;
       Invalidate();  // triggers Paint event
    }
    

    If you’re drawing bitmaps, I would load the bitmap once and store it as a class variable. This way you don’t need to hit the hard drive each time you want to draw. Dispose of the bitmap when you dispose of your class (in this case, your window).

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

Sidebar

Ask A Question

Stats

  • Questions 391k
  • Answers 391k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have to assign an eventhandler on the datagrid, and… May 15, 2026 at 1:17 am
  • Editorial Team
    Editorial Team added an answer Taken from MSDN:- When considering MarshalByRefObject objects, all calls on… May 15, 2026 at 1:17 am
  • Editorial Team
    Editorial Team added an answer In this scenario, I would use ReaderWriterLockSlim which allows you… May 15, 2026 at 1:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.