Some days ago in the forum posted a post, 100 points to seek the "rubber Strip" method drawing code. The effect is not very good, so they refer to the code to the user to write a new, solve the problem of drawing and redrawing. Because only write part, so the function is limited, at the same time perhaps the algorithm is not very good, hope everybody pointing!! The form contains only one pictrueBox1, first putting the code down:
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using System.Drawing.Drawing2D;
Namespace Gdi_ Practice
{
<summary>
Summary description of the Form1.
</summary>
public class Form1:System.Windows.Forms.Form
{
Public System.Windows.Forms.PictureBox PictureBox1;
Private point p1 = point.empty, p2 = point.empty;
private bool Ismousedown = False, Ismouseup = false;
ArrayList AddArray = new ArrayList ();
public struct Sharptype
{
public string type;
Public point P1, p2;
Public Color ForeColor, BackColor;
Public Brush Brush;
Public Sharptype (String type, point P1, point P2, color foreColor, color BackColor, Brush Brush)
{
This.type = type;
This.p1 = p1;
THIS.P2 = p2;
This.forecolor = ForeColor;
This.backcolor = BackColor;
This.brush = brush;
}
Public Form1 ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
//
TODO: Add any constructor code after the InitializeComponent call
//
}
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This.picturebox1 = new System.Windows.Forms.PictureBox ();
This. SuspendLayout ();
//
PictureBox1
//
This.pictureBox1.BackColor = System.Drawing.Color.White;
This.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
This.pictureBox1.Location = new System.Drawing.Point (0, 0);
This.pictureBox1.Name = "PictureBox1";
This.pictureBox1.Size = new System.Drawing.Size (432, 397);
This.pictureBox1.TabIndex = 0;
This.pictureBox1.TabStop = false;
This.pictureBox1.Paint + = new System.Windows.Forms.PaintEventHandler (this.picturebox1_paint);
This.pictureBox1.MouseUp + = new System.Windows.Forms.MouseEventHandler (this.picturebox1_mouseup);
This.pictureBox1.MouseMove + = new System.Windows.Forms.MouseEventHandler (this.picturebox1_mousemove);
This.pictureBox1.MouseDown + = new System.Windows.Forms.MouseEventHandler (This.picturebox1_mousedown);
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (432, 397);
This. Controls.Add (This.picturebox1);
This. Name = "Form1";
This. Text = "Form1";
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Form1 ());
}
private void Picturebox1_mousedown (object sender, System.Windows.Forms.MouseEventArgs e)
{
if (! Ismouseup)
{
This.ismousedown = true;
THIS.P1 = new Point (e.x, e.y);
}
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.