Click here to Skip to main content
15,917,928 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
PLS..
PLS..
how to draw Rectangle using mouse on the form..
Posted
Comments
fkassaie 3-Nov-13 3:06am    
Hi,
I think these link will be useful for you:
http://www.techotopia.com/index.php/Drawing_Graphics_in_Visual_Basic
http://social.msdn.microsoft.com/Forums/en-US/39d5e468-f76b-4d44-954b-d220eed57cf4/make-drawings-with-mouse-in-window-form-in-vbnet-2005-or-2010?forum=Vsexpressvb

Since you refer to "on the form" I will assume this is not VB.NET - which is broswer based - but WinForms, which isn't.

It's not too difficult:
1) Handle the MouseDown, MouseMove and MouseUp events for teh form. Also Handle the Paint event.
2) Create three class level variables: a Point called "start", a Point called "current" and a bool called "moving".
3) In the MouseDown handler, set moving to true and start to the current mouse position.
4) In the MouseUp event, set moving to false
5) In the MouseMove event, look at moving. If it is true, set current to the current mouse position, and call the Invalidate method.
6) Invalidate causes the form to be re-drawn, causing the Paint event handler to be called.
7) In the Paint handler, use the PaintEventArgs parameter Graphics property, and call it's DrawRectangle method - it has an overload that takes two points.

Done!
 
Share this answer
 
Hi, I think these link will be useful for you:
http://www.techotopia.com/index.php/Drawing_Graphics_in_Visual_Basic http://social.msdn.microsoft.com/Forums/en-US/39d5e468-f76b-4d44-954b-d220eed57cf4/make-drawings-with-mouse-in-window-form-in-vbnet-2005-or-2010?forum=Vsexpressvb
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900