| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 815 人关注过本帖
标题:[求助]怎么显示画图像时的效果?
只看楼主 加入收藏
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
结帖率:100%
收藏
 问题点数:0 回复次数:7 
[求助]怎么显示画图像时的效果?

有人能帮我改一下下面的代码吗?这个里面在画线的时候不显示。当鼠标放下才显示结果。我想让鼠标在动的时候显示效果!!!别请高手改一下看看怎么能让画好的图像能通过鼠标来改变画好的图像的大小和位置。请高手指点

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;
}



}
}
}

搜索更多相关主题的帖子: using 画图 鼠标 System 效果 
2006-07-21 13:19
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
收藏
得分:0 
没有人解决????????????????

2006-07-21 14:03
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
public ff mark1;
public ff mark2;
这2句什么意思袄
ff是什么呀

此号自封于2006年11月30日
2006-07-21 14:06
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
收藏
得分:0 

ff是用户自定义控件。。它的原源是
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace WindowsApplication9
{
/// <summary>
/// ff 的摘要说明。
/// </summary>
public class ff : System.Windows.Forms.UserControl
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public ff()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
this.BackColor=Color.Red;

// TODO: 在 InitializeComponent 调用后添加任何初始化

}
public Point Center
{
get
{
return new Point(Location.X+2,Location.Y+2);
}
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// ff
//
this.Name = "ff";
this.Size = new System.Drawing.Size(8, 8);
this.Load += new System.EventHandler(this.ff_Load);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ff_MouseDown);

}
#endregion

private void ff_Load(object sender, System.EventArgs e)
{

}

public int a,b,c,d,mm_x,mm_y;
private void ff_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{

}
}
}


2006-07-21 14:31
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
已经可以调试了
不过我还没画出来

此号自封于2006年11月30日
2006-07-21 16:59
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 

[CODE]using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace BC_CN_TEST1
{
/// <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();
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.Click += new System.EventHandler(this.pictureBox1_Click);
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(392, 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.TransparentColor = System.Drawing.Color.Transparent;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(392, 269);
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;
Pen linePen=new Pen(Color.Red);
Pen rectPen=new Pen(Color.Black);
Pen EllipsePen=new Pen(Color.Red);

Graphics g=this.pictureBox1.CreateGraphics();
g.DrawLine(linePen, a ,b ,c ,d);

}
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Graphics g=this.pictureBox1.CreateGraphics();
g.Clear (Color.Black );
c=e.X ;
d=e.Y ;
Pen linePen=new Pen(Color.Red);
Pen rectPen=new Pen(Color.Black);
Pen EllipsePen=new Pen(Color.Red);

g.DrawLine(linePen, a ,b ,c ,d);

}
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;
}



}
private void pictureBox1_Click(object sender, System.EventArgs e)
{


}
}
}[/CODE]

目前做到这个情况了
那个线可以跟着鼠标走了
你再调调吧
下班了先撤退了


此号自封于2006年11月30日
2006-07-21 17:03
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
結果是不是顯示在MouseUp裡面
仍到mousemove裡面看看

先用個變量確定有mousedown mousemove才執行結果

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-07-21 17:06
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
收藏
得分:0 
6楼那位老兄..你的那个代码不能实现画线和画矩形了..画后窗体上什么都不会保存的

2006-07-22 10:46
快速回复:[求助]怎么显示画图像时的效果?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.059658 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved