public partial class Draw : Form
{
Graphics myGraphics;
int x;
int y;
int oldX;
int oldY;
Pen myPen;
bool ifDrwa;
Stack<Point> pointStack;//用来保存所有鼠标画过的点,在重绘时候画
public Draw()
{
ifDrwa = false;//设置为不画
myGraphics = this.CreateGraphics();
myPen=new Pen(Color.Black);
InitializeComponent();
this.SetDesktopLocation(0, 0);
pointStack = new Stack<Point>();
// this.Size.Width = 768;
// this.Size.Height = 1024;
} private void Draw_MouseDown(object sender, MouseEventArgs e)
{
ifDrwa = true;//鼠标按下时候才开始画
oldX = e.X;
oldY = e.Y;
} private void Draw_MouseMove(object sender, MouseEventArgs e)
{
if (ifDrwa == true)
{
//将鼠标划过的地方全部入栈
Point tempPoint = new Point(this.oldX, this.oldY);
pointStack.Push(tempPoint);//鼠标不停的滑动,就不停的入栈
myGraphics.DrawLine(myPen, oldX, oldY, e.X, e.Y);
//画完后,将当前的鼠标位置记下
oldX = e.X;
oldY = e.Y;
}
} private void Draw_MouseUp(object sender, MouseEventArgs e)
{
//若鼠标建起,则停止画
ifDrwa = false;
}
画线可以实现,但是重绘时候就没了,希望知道怎么保存先前画的线
{
Graphics myGraphics;
int x;
int y;
int oldX;
int oldY;
Pen myPen;
bool ifDrwa;
Stack<Point> pointStack;//用来保存所有鼠标画过的点,在重绘时候画
public Draw()
{
ifDrwa = false;//设置为不画
myGraphics = this.CreateGraphics();
myPen=new Pen(Color.Black);
InitializeComponent();
this.SetDesktopLocation(0, 0);
pointStack = new Stack<Point>();
// this.Size.Width = 768;
// this.Size.Height = 1024;
} private void Draw_MouseDown(object sender, MouseEventArgs e)
{
ifDrwa = true;//鼠标按下时候才开始画
oldX = e.X;
oldY = e.Y;
} private void Draw_MouseMove(object sender, MouseEventArgs e)
{
if (ifDrwa == true)
{
//将鼠标划过的地方全部入栈
Point tempPoint = new Point(this.oldX, this.oldY);
pointStack.Push(tempPoint);//鼠标不停的滑动,就不停的入栈
myGraphics.DrawLine(myPen, oldX, oldY, e.X, e.Y);
//画完后,将当前的鼠标位置记下
oldX = e.X;
oldY = e.Y;
}
} private void Draw_MouseUp(object sender, MouseEventArgs e)
{
//若鼠标建起,则停止画
ifDrwa = false;
}
画线可以实现,但是重绘时候就没了,希望知道怎么保存先前画的线
解决方案 »
- Excel导出问题
- 求一正则
- 变数的阶层、程序阶层变量 中的的阶层什么意思
- c#中调用DLL(C++)的一个问题,请高手解决
- Form_load里给ListBox控件绑数据,也引发ListBox_SelectedIndexChanged事件?
- 我在datagrid中定义了currentcellchanged事件,但为什么第一次点击第一行时,不能产生事件呢???
- 很奇怪,vs.net2003启动问题,up有分
- 百思不得其解 http://csinjoin.hnu.cn/3.jpg 先不放分,搞定后例外ID给180
- 问个Socket问题,在同一机子上打开2个客户端就出错,帮忙看下这段代码:
- 小白求教:如何自动实现网页数据下载
- 是去是留,请兄弟们指点一下!
- 用Graphics绘图如何实现移动图形?
或者放入一个纪录文件!xxx.txt
Graphics g2=Graphics.FromImage(b);然后画的时候同时在g2里画,完了再保存b就是了