日期:2014-05-17  浏览次数:20733 次

有点想不明白...
Dispose 不是把目标销毁么?


代码贴上:


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 Dispose销毁目标
{
    public partial class Form1 : Form
    {
        
        Point start, end;
        bool mousedown = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (mousedown)
            {
                Bitmap bmp = new Bitmap(this.Width, this.Height);
                Graphics gr = Graphics.FromImage(bmp);
                //Graphics gr = this.CreateGraphics();
                gr.DrawRectangle(new Pen(Color.Red),start.X,start.Y,e.X-start.X,e.Y-start.Y);
                
                Graphics tg = this.CreateGraphics();
                tg.DrawImage(bmp, 0, 0);
                gr.Dispose();
                
            }