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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:47:24+00:00 2026-06-09T10:47:24+00:00

I owned complex drawing code with GDI+ which draws something like a chart on

  • 0

I owned complex drawing code with GDI+ which draws something like a chart on a user control.
If the user clicks with control pressed, a vertical marker line in dash style should be shown.

Now I look for a way to extend the drawing code without touching the complex drawing code.

I created a marker class which attaches to the mouse-up event of the user control.
In the eventhandler a check against (ModifierKeys == Keys.Control) is done.

If the user holds the control key and click with the left mouse button the draw method of the marker class is called with the Graphics object of the usercontrol as a parameter.

The current behaviour is that for each click a new line is drawn, but the line should be deleted and a new one should be drawn.

How can i erase the drawed line?

Do I have to redraw the comlete content of the user control?

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

    The answer here is clearly yes. With GDI+ you just draw directly on a bitmap buffer, so if you want to undo a previous drawing operation you can do one of those things (depending on the complexity of the issue and performance):

    • restore the bytes that have been changed on the bitmap buffer
    • reload a previous state of the drawing bitmap

    A simple solution would be to have 2 bitmaps (something like that is usually called double buffering). One that is shown currently (and contains the final state) and one that is used for preview only. The preview one is always a copy of the first one – just with current modifications.

    So basic algorithm for this simple implementation:

    • start with two bitmaps (blank but identical sizes) [named A and B]
    • if the user draws a line always make a copy of the bitmap A in B and draw on B – show B
    • if the user finishes the line then make a copy of B in A and again – show B

    So always show the preview bitmap, which is just a modified bitmap of the original one.

    Here is an example programming code in C# (assuming all events are connected and the preview Bitmap, B, is the picture box itself (which is just named pictureBox1 here):

    Bitmap bmp;
    bool isDrawing;
    Point previous;
    
    void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        isDrawing = true;
        previous = e.Location;
    }
    
    void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        isDrawing = false;
    }
    
    void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        if (isDrawing)
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                double wf = (double)bmp.Width / (double)pictureBox1.Width;
                double hf = (double)bmp.Height / (double)pictureBox1.Height;
                g.ScaleTransform((float)wf, (float)hf);
                g.DrawLine(Pens.Black, e.Location, previous);
            }
    
            pictureBox1.Refresh();
            previous = e.Location;
        }
    }
    

    This code will do everything to display drawing a straight line from a point to another by simply pressing the left mouse button.

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

Sidebar

Related Questions

I have a product which is owned by a user in my CouchDB. product
I have to use the EXEC family to find the process owned (the user)
Id like to find out ( and delete ) all the databases owned by
Can/should One use any ORM Solution is a Complex Situation like this ? can
Suppose you have a window nib, owned by a NSWindowController which loads the nib.
If i set a owned window like that : OwnedWindow ownedWindow = new OwnedWindow();
I want to create a trigger owned by user A for a table that
I have been given a code-base that was owned by someone else. I have
The repository is owned by user root, and group dev Another user is running
I have a panel xib which is owned by class FooController. FooController also has

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.