Search code examples
c#-3.0mousedrawrectangle

How to draw a rectangle in C# using a mouse


I want to draw a rectangle on a form in C#. I read and found this article. Are there any samples or tutorials available ? The article was not very helpful.


Solution

  • The article you linked appears to be C++, which may explain why it didn't help you much.

    If you create events for MouseDown and MouseUp, you should have the two corner points you need for a rectangle. From there, it's a matter of drawing on the form. System.Drawing.* should probably be your first stop. There are a couple of tutorials linked below:

    Drawing with Graphics in WinForms using C#

    Draw a rectangle using Winforms (StackOverflow)

    Graphics Programming using C#