namespace DrawCurve
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private Image theImage; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
// //SetStyle(ControlStyles.Opaque, true);
theImage = new Bitmap("aaa.jpg");

} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
theImage.Dispose();
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnClose = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.dlgSave = new System.Windows.Forms.SaveFileDialog();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
// 
// btnClose
// 
this.btnClose.Location = new System.Drawing.Point(192, 232);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 1;
this.btnClose.Text = "Close";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
// 
// btnSave
// 
this.btnSave.Location = new System.Drawing.Point(24, 232);
this.btnSave.Name = "btnSave";
this.btnSave.TabIndex = 2;
this.btnSave.Text = "Save";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
// 
// dlgSave
// 
this.dlgSave.FileName = "doc1";
// 
// pictureBox1
// 
this.pictureBox1.BackColor = System.Drawing.SystemColors.Window;
this.pictureBox1.Location = new System.Drawing.Point(16, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(264, 208);
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
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(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
  this.pictureBox1,
  this.btnSave,
  this.btnClose});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
} private bool isDown;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.SaveFileDialog dlgSave;
private System.Windows.Forms.PictureBox pictureBox1;
private Point lastDot;
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
} private void btnSave_Click(object sender, System.EventArgs e)
{
if (this.dlgSave.ShowDialog() == DialogResult.OK)
{
using (Graphics g = this.pictureBox1.CreateGraphics())
{
g.DrawImage(theImage, this.pictureBox1.ClientRectangle);
}
theImage.Save(this.dlgSave.FileName, ImageFormat.Jpeg);
}
} private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
isDown = true;
lastDot.X = e.X;
lastDot.Y = e.Y;
} private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
isDown = false;
} private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isDown)
{
using (Graphics g = Graphics.FromImage(theImage))
{
using (Pen blackPen = new Pen(Color.Black, 1))
{
g.DrawLine(blackPen, new Point(lastDot.X, lastDot.Y), new Point(e.X, e.Y));
lastDot.X = e.X;
lastDot.Y = e.Y;
}
}
using (Graphics disg = this.pictureBox1.CreateGraphics())
{
disg.DrawImage(theImage, this.pictureBox1.ClientRectangle);
}
}
}