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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:00:40+00:00 2026-05-14T02:00:40+00:00

i m currently working on visual c++ 2008 express edition.. in my project i

  • 0

i m currently working on visual c++ 2008 express edition..
in my project i have a picturebox which contains an image, now i have to draw a rectangle to enaable the user to select a part of the image..
I have used the “MouseDown” event of the picturebox and the below code to draw a rectangle:

Void pictureBox1_MouseDown(System::Object^ sender, Windows::Forms::MouseEventArgs^  e)   
                 {  
             Graphics^ g = pictureBox1->CreateGraphics();  
             Pen^ pen = gcnew Pen(Color::Blue);  
             g->DrawRectangle( pen , e->X ,e->Y,width,ht);           
         }

now in the “DrawRectangle” the arguments “width” and “ht” are static, so the above code results in the drawing of a rectangle at the point where the user presses the mouse button on the image in picturebox…
i want to allow the user to be able to drag the cursor and draw a rectangle of size that he wishes to..
Plz help me on this..
Thanx..

  • 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-14T02:00:40+00:00Added an answer on May 14, 2026 at 2:00 am

    You shouldn’t draw directly to your window in your event handlers – all drawing should be in your Paint event handler.

    There is a lot more you can do to make it work well, but the core of the technique you need is:

    To move a rectangle around as the user drags the mouse, you have to handle Mouse Moved events. Each time you get one, you need to Invalidate() to cause a redraw of your window. In your Paint handler, if the mouse button is down, get the mouse pointer position and draw the rectangle at that location.

    That will get you started, but it will have a few problems – the window will flicker as it constantly redraws, and it may be a bit slow.

    There are other things you can do to improve this, including:

    • Only Invalidate the parts of the form that you need to (where the old rectangle needs to be erased from, and where the new rectangle needs to be drawn)

    • After Invalidate(), call Update() immediately to cause the redraw to happen as soon as possible

    • “double buffered” rendering, and/or storing the window content in an offscreen bitmap so that you can re-render the background with the rectangle on top more quickly and without flicker. (But this is quite an advanced technique).

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

Sidebar

Related Questions

I am working in Visual Studio 2008 and have a Windows Forms project +
Using Visual Studio 2008 (C#) I have to make a working clock (digital) with
I am currently using Visual Studio 2008 with Devexpress 10.2. My sum for some
I'm working on an application which walks through every file in some directories and
I'm a newbie in programming and visual basic 2008 language. I'm learning to use
I am attempting to create a CustomControl in C# which contains a Delphi TFrame,
Visual Studio 2008 | Silverlight 3 | SQL Server 2005 | Domain Services Class
I'm working on a pretty tricky problem that I've been on for literally a
Prior to Visual Studio 2005, the bookmark feature worked perfectly. Then starting with VS
I am trying to use the MailMessage class to construct e-mail messages that are

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.