有人能帮我改一下下面的代码吗?这个里面在画线的时候不显示。当鼠标放下才显示结果。我想让鼠标在动的时候显示效果!!!别请高手改一下看看怎么能让画好的图像能通过鼠标来改变画好的图像的大小和位置。请高手指点
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace WindowsApplication9
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ImageList imageList1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
public struct line
{
public ff mark1;
public ff mark2;
public int Width;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(8, 48);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(280, 208);
this.pictureBox1.TabIndex = 0;
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_1);
//
// button1
//
this.button1.Location = new System.Drawing.Point(312, 56);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4,
this.toolBarButton5});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(368, 41);
this.toolBar1.TabIndex = 2;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.Text = "2";
//
// toolBarButton3
//
this.toolBarButton3.Text = "3";
//
// toolBarButton4
//
this.toolBarButton4.Text = "4";
//
// toolBarButton5
//
this.toolBarButton5.Text = "5";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(368, 266);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
public bool aa;
public bool bb;
public bool cc;
public bool dd;
public bool ff;
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if(e.Button==this.toolBarButton1)
{
aa=true;
bb=false;
cc=false;
dd=false;
ff=false;
}
if(e.Button==this.toolBarButton2)
{
bb=true;
aa=false;
cc=false;
dd=false;
ff=false;
}
if(e.Button==this.toolBarButton3)
{
cc=true;
aa=false;
bb=false;
dd=false;
ff=false;
}
if(e.Button==this.toolBarButton4)
{
dd=true;
aa=false;
cc=false;
bb=false;
ff=false;
}
if(e.Button==this.toolBarButton5)
{
ff=true;
aa=false;
cc=false;
dd=false;
bb=false;
}
}
public int a,b,c,d,mm_x,mm_y;
private void pictureBox_Paint(object sender,System.Windows.Forms.PaintEventArgs e)
{
// Pen linePen=new Pen(Color.Red,1);
}
private void pictureBox1_MouseDown_1(object sender, System.Windows.Forms.MouseEventArgs e)
{
a=e.X;
b=e.Y;
}
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
mm_x=e.X;
mm_y=e.Y;
Pen linePen=new Pen(Color.Black);
// Pen rectPen=new Pen(Color.Red);
Graphics g=this.pictureBox1.CreateGraphics();
}
private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
c=e.X;
d=e.Y;
Pen linePen=new Pen(Color.Red);
Pen rectPen=new Pen(Color.Black);
Pen EllipsePen=new Pen(Color.Red);
Graphics g=this.pictureBox1.CreateGraphics();
if(aa==true)
{
g.DrawLine(linePen, a ,b ,c ,d);
// ff mark1=new ff();
// mark1.Location=new Point(a,b);
// pictureBox1.Controls.Add(mark1);
//
// ff mark2=new ff();
// mark2.Location=new Point(c,d);
// pictureBox1.Controls.Add(mark2);
aa=false;
}
if(bb==true)
{
g.DrawRectangle(rectPen,a,b,c-a,d-b);
// ff mark1=new ff();
// mark1.Location=new Point(a,b);
// pictureBox1.Controls.Add(mark1);
//
// ff mark2=new ff();
// mark2.Location=new Point(c,d);
// pictureBox1.Controls.Add(mark2);
bb=false;
}
if(cc==true)
{
g.DrawEllipse(EllipsePen,a,b,c-a,d-b);
cc=false;
}
if(dd==true)
{
g.DrawEllipse(EllipsePen,a,b,c-a,c-a);
dd=false;
}
}
}
}