Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET graphics Mouse
Hi
 
My question is that i am having video stream from my webcam.i am displaying it on my picture box.Now i want user to to click on four locations and i want a rectangle drawn on using those four locations i-e first click will be the starting point so on.
I am a beginner so please excuse if you feel its too simple.I can draw a rectangle using hard coded locations.Following is the code i have in my event handler that has the new frame.
   Pen pen = new Pen(Color.Red, 2);
   Graphics g = Graphics.FromImage(bitmap);     
   g.DrawRectangle(pen, 30, 30, 60, 30); 
but as you see i have hard coded initial x,y,width,height i want them to be user defined clicks.
 
regards
Posted 11-Nov-12 20:04pm
Comments
Sergey Alexandrovich Kryukov at 12-Nov-12 1:29am
   
What do you want it to draw on, ultimately, on a screen or a bitmap? If a bitmap, and the mouse is on the screen, how it supposed to be?
--SA
loraloper_22 at 12-Nov-12 1:46am
   
i want to draw it on the bitmap now when user clicks on four locations i want to store them
Sergey Alexandrovich Kryukov at 12-Nov-12 2:27am
   
Do you mean that a bitmap is rendered in some control, than -- what? Do you need to draw a rectangle as you move the mouse? Otherwise you would not see the data. And are you sure you really want to draw on a bitmap? What's the goal of all of it?
--SA
loraloper_22 at 12-Nov-12 2:34am
   
I have done it anyways.The goal was to draw an out of bound region when ever an object moves into it raise an alarm.
regards

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First off, you don't want four locations - they will not necessarily describe a rectangle, or even a parallelogram. Two points define a rectangle: either TLHC and BRHC or TRHC and BLHC is sufficient.
 
Exactly how you pick up the mouse locations will depend on where you are drawing your bitmap: if it is on a form surface then just handle the Form.MouseDown or Form.MouseClick event - they both give your the mouse coordinates as part of the MouseEventArgs parameter.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100