表单大小调整时出现问题

表单大小调整时出现问题

本文介绍了表单大小调整时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#2005编写绘图程序.
代码:

I''m writing a drawing program with C # 2005.It has worked.

Code:

 private bool mouseDown = false ;
 private Point lastPoint = Point.Empty;
 private string color = "blue" ;
 private Graphics g;
 private Pen p;
 public Form1()
{
    InitializeComponent();
    g = CreateGraphics();
    p = new Pen(Color.FromName(color),3);
}



private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    mouseDown = true;

}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
    mouseDown = false;
}



private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    if(lastPoint.Equals(Point.Empty))
        lastPoint = new Point( e.X, e.Y ) ;
    if (mouseDown){
     Point pMousePos = new Point( e.X, e.Y ) ;
     g.DrawLine( p, pMousePos, lastPoint ) ;
 }
 lastPoint = new Point ( e.X, e.Y ) ;
 //p.Dispose();
 //g.Dispose();

}



我正在用C#2005编写绘图程序.

成功了.

但是,当我调整窗体的大小时,只能绘制Form1的旧宽度和高度.

调整窗体大小时如何更改画布大小?

我尝试了p.Dispose();g.Dispose();.但是失败了.
谢谢朋友.我找到了这段代码:



I''m writing a drawing program with C # 2005.

It succeeded.

But when I resize the Form, I can only draw in the old width and height of Form1.

How to I change the canvas size when Form resize?

I tried p.Dispose(); and g.Dispose();. But failed.
Thank friends.I found this code:

List<Point> points = new List<Point>();

       private void Form1_MouseMove(object sender, MouseEventArgs e)
       {
           if (e.Button == MouseButtons.Left)
           {
               points.Add(e.Location);

               Invalidate();
           }

       }

       private void Form1_Paint(object sender, PaintEventArgs e)
       {
           if (points.Count > 2)
           {
               e.Graphics.DrawLines(Pens.Black, points.ToArray());
           }

       }


唯一的问题是,当MouseUp


only a problem is can not draw a new line when the MouseUp

推荐答案



这篇关于表单大小调整时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:18