楼主想要通过按钮(只有在点击后才会出现那张图自己画的图)来实现在Form1上画一张图(图的大小大于窗口的大小,所以设置了滚动条),但是在点击以后就在窗口中出现了话的一部分,但是当楼主想拖动滚动条的时候不仅以前未显示的部分没有出现,而且原来的那部分也不见了;代码如下using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 重绘1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.AutoScroll = true;
            this.BackColor = Color.Pink;
            this.AutoScrollMinSize = new Size(10000, 10000);
        }
       private void weizhi(PaintEventArgs e)
        {
            Point startPoint=new Point (0,0);
            Size  location = new Size(1000, 1000);
            Rectangle rectangle = new Rectangle(startPoint,location);
            e.Graphics.Clip = new Region(rectangle ); 
        }
       private void button1_Click(object sender, EventArgs e)
        {
            
            huahua();            
        }
        private void huahua()
        {
            
            Graphics g = CreateGraphics();
            
            Point startPoint = new Point(0, 0);
            Point endPoint = new Point(800, 800);
            SolidBrush brush = new SolidBrush(Color.Green);
            Pen pen = new Pen(brush, 18);
            g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
            g.FillEllipse(brush, 0, 0, 120, 120);
            g.DrawEllipse(pen, 120, 120, 300, 300);
            g.DrawLine(pen, startPoint, endPoint);
            g.Dispose();
            pen.Dispose();this.BackColor = Color.Pink;
            brush.Dispose();
        }        
        private void button2_Click(object sender, EventArgs e)
        {
            Graphics g = CreateGraphics();
            g.Clear(Color.White);
            g.Dispose();
        }
    }
}
重绘

解决方案 »

  1.   

    要在 paint事件里处理绘制  要不窗体发生重绘你的画面就不见了
      

  2.   


    public partial class Form1 : Form
    {
        bool bPaint = false;
        public Form1()
        {
            InitializeComponent();        this.AutoScroll = true;
            this.BackColor = Color.Pink;
            this.AutoScrollMinSize = new Size(10000, 10000);        Paint += new PaintEventHandler(Form1_Paint);
        }    void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (bPaint)
            {
                huahua(e.Graphics);
            }
        }    private void weizhi(PaintEventArgs e)
        {
            Point startPoint = new Point(0, 0);
            Size location = new Size(1000, 1000);
            Rectangle rectangle = new Rectangle(startPoint, location);
            e.Graphics.Clip = new Region(rectangle);
        }    private void button1_Click(object sender, EventArgs e)
        {
            bPaint = true;
            this.Invalidate();
        }    private void huahua(Graphics g)
        {        //Graphics g = CreateGraphics();        Point startPoint = new Point(0, 0);
            Point endPoint = new Point(800, 800);
            SolidBrush brush = new SolidBrush(Color.Green);
            Pen pen = new Pen(brush, 18);
            g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
            g.FillEllipse(brush, 0, 0, 120, 120);
            g.DrawEllipse(pen, 120, 120, 300, 300);
            g.DrawLine(pen, startPoint, endPoint);
            // g.Dispose();
            pen.Dispose();
            this.BackColor = Color.Pink;
            brush.Dispose();
        }    private void button2_Click(object sender, EventArgs e)
        {
            bPaint = false;
            // Graphics g = CreateGraphics();
            // g.Clear(Color.White);
            // g.Dispose();        this.BackColor = Color.White;
        }
    }
      

  3.   

    huahua(e.Graphics)中的参数是什么,哪里来的?有什么用?
      

  4.   


    void Form1_Paint(object sender, PaintEventArgs e)在重绘事件中,事件参数PaintEventArgs ,这个参数的 Graphics也就是当前窗体的绘图表面 
      

  5.   


    void Form1_Paint(object sender, PaintEventArgs e)在重绘事件中,事件参数PaintEventArgs ,这个参数的 Graphics也就是当前窗体的绘图表面 当然,你也可以这样huahua(CreateGraphics())是一样的
      

  6.   

    那个又晕了,重绘事件是什么?是point事件吗?还是说point事件触发了重绘事件;
    void Form1_Paint(object sender, PaintEventArgs e)这个是什么意思?是事件还是函数?有什么用,对于Paint 我一直不能理解,
      

  7.   

    楼主想知道更多,就去探究下windows gdi吧