© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
13 replies
CHΔNGΕ

drawing Rectangles in winforms c# help

Point shapestartP = new Point(0, 0);
 private void picBoxMain_MouseUp(object sender, MouseEventArgs e)
 {
     flagDraw = false;
     g = Graphics.FromImage(bm);



     if (flagDrawingTool == "Rectangle")
     {
         g.DrawRectangle(pen, shapestartP.X, shapestartP.Y,Math.Abs(e.Location.X - shapestartP.X ),Math.Abs(e.Location.Y - shapestartP.Y));
     }
     g.Dispose();
     picBoxMain.Invalidate();


 }
private void picBoxMain_MouseDown(object sender, MouseEventArgs e)
{
    
    shapestartP = e.Location;
}
Point shapestartP = new Point(0, 0);
 private void picBoxMain_MouseUp(object sender, MouseEventArgs e)
 {
     flagDraw = false;
     g = Graphics.FromImage(bm);



     if (flagDrawingTool == "Rectangle")
     {
         g.DrawRectangle(pen, shapestartP.X, shapestartP.Y,Math.Abs(e.Location.X - shapestartP.X ),Math.Abs(e.Location.Y - shapestartP.Y));
     }
     g.Dispose();
     picBoxMain.Invalidate();


 }
private void picBoxMain_MouseDown(object sender, MouseEventArgs e)
{
    
    shapestartP = e.Location;
}

This code is flawed as when u drag the cursor from bottom to up it stills draws the rectangle upwards. Any suggestions?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

please help!!! (winforms c#)
C#CC# / help
3y ago
✅ c# winforms toggle switch help
C#CC# / help
3y ago
c# winforms size
C#CC# / help
9mo ago
C# WinForms Chat
C#CC# / help
2y ago