C # Draw and fill the line with the mouse in the window

Source: Internet
Author: User

Namespace WindowsApplication1
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Point p1;
Point p2;
ArrayList mya = new ArrayList ();
Private void form=mousedown (object sender, MouseEventArgs e)
{
Point p = new Point (e. X, e. Y );
If (p1.X = 0 & p1.Y = 0)
{
P1 = p;
Mya. Add (p1 );
}
}

Private void form=mouseup (object sender, MouseEventArgs e)
{
Point p = new Point (e. X, e. Y );
P2 = p;
Mya. Add (p2 );
Graphics g = this. CreateGraphics ();
G. DrawLine (Pens. Red, p1, p2 );
P1 = p2;
}

Private void button#click (object sender, EventArgs e)
{
Int number = mya. Count;
Point [] myp = new Point [number];
Object [] ob = new Object [number];

For (int I = 0; I <number; I ++)
{
Ob [I] = mya [I];
Myp [I] = (Point) ob [I];
}
Graphics g = this. CreateGraphics ();
G. DrawPolygon (Pens. Red, myp );
G. FillPolygon (Brushes. Red, myp );
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.