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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:21:03+00:00 2026-05-23T05:21:03+00:00

When the mouse is clicked at a point on the picture box during the

  • 0

When the mouse is clicked at a point on the picture box during the run time( i.e when the image is loaded) it should change color of the pixels at that location.i have this piece of code showing error.

    private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
    {
        Bitmap bm=new Bitmap(1,1);
        bm.SetPixel(0,0,Color.Red);
        e.Graphics.DrawImageUnscaled(bm,e.X,e.Y);
    }

the error is ‘System.Windows.Forms.MouseEventArgs’ does not contain a definition for ‘Graphics’ and no extension method ‘Graphics’ accepting a first argument of type ‘System.Windows.Forms.MouseEventArgs’ could be found (are you missing a using directive or an assembly reference?)

even though i included system.drawing it is showing this error.

  • 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-23T05:21:04+00:00Added an answer on May 23, 2026 at 5:21 am

    Try changing the image in the picturebox instead of trying to redraw it, as the MouseEventArgs does not contain any Graphics property.

    Example:

    int radius = 3; //Set the number of pixel you wan to use here
     //Calculate the numbers based on radius
    int x0 = Math.Max(e.X-(radius/2),0),
        y0 = Math.Max(e.Y-(radius/2),0),
        x1 = Math.Min(e.X+(radius/2),pictureBox1.Width),
        y1 = Math.Min(e.Y+(radius/2),pictureBox1.Height);
    Bitmap bm = pictureBox1.Image as BitMap; //Get the bitmap (assuming it is stored that way)
    for (int ix = x0; ix < x1; ix++)
    {
       for (int iy = y0; iy < y1; iy++)
       {
        bm.SetPixel(ix,iy, Color.Read); //Change the pixel color, maybe should be relative to bitmap
       }
    }
    pictureBox1.Refresh(); //Force refresh
    

    EDIT: Alowed multiple pixels to be selected in accordance with a fill radius

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

Sidebar

Related Questions

<div><span>shanghai</span><span>male</span></div> For div like above,when mouse on,it should become cursor:pointer,and when clicked,fire a javascript
I am attempting to obtain class-data associated with a mouse-clicked ImageButton; which ImageButton is
I want to make a splash screen, which cannot be clicked/selected by mouse/UI. As
I need to move a multiple textboxes with a mouse cursor. I decided that
HI Everyone, How can i find line number in events like mouse clicked, key
When mouse nears top edge of scrollpane, it scrolls up until it reaches the
Struggling with styling the mouse over for a button ... I have managed to
I often (using the mouse) switch between 1 of 3 favorite folders under my
If a mouse has other buttons in addition to the standard left/right/middle (e.g. forward/back),
I have set mouse events on a Canvas as follows: <Canvas MouseUp=CanvasUp MouseDown=CanvasDown MouseMove=CanvasMove>

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.