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

如何在PictureBox中实现选择框功能
如何在PictureBox中实现选择框功能,即在PictureBox中按下鼠标左键不松开,然后拖出一个矩形框,当松开鼠标时这个矩形框消失

------解决方案--------------------
帮你写一个小例子


using System;
using System.Drawing;
using System.Windows.Forms;
namespace Test
{
    public partial class Form1 : Form
    {
        private Point startPoint;
        private Point endPoint;
        private bool isDrawing = false;
        private Bitmap memoryBuffer;
        public Form1()
        {
            InitializeComponent();
            memoryBuffer = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            pictureBox1.MouseUp += new MouseEventHandler(pictureBox1_MouseUp);
            pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
            pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
        }

        void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            isDrawing = false;
        }
        void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            startPoint = new Point(e.X, e.Y);
            isDrawing = true;
        }
        void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            endPoint = new Point(e.X, e.Y);
            drawSelectedRect();
   &nb