程序代码:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication29
{
public partial class Form1 : Form
{
public Point firstPoint = new Point(0, 0); //鼠标第一点
public Point secondPoint = new Point(0, 0); //鼠标第二点
public bool begin = false; //是否开始画矩形
Graphics g;
public Form1()
{
InitializeComponent();
g = this.CreateGraphics();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
begin = true;
firstPoint = new Point(e.X, e.Y);
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (begin)
{
g.Clear(this.BackColor);
//获取新的右下角坐标
secondPoint = new Point(e.X, e.Y);
int minX = Math.Min(firstPoint.X, secondPoint.X);
int minY = Math.Min(firstPoint.Y, secondPoint.Y);
int maxX = Math.Max(firstPoint.X, secondPoint.X);
int maxY = Math.Max(firstPoint.Y, secondPoint.Y);
//画框
g.DrawRectangle(new Pen(Color.Red), minX, minY, maxX - minX, maxY - minY);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
begin = false;
}
}
}
怎么放大我还不知道
[
本帖最后由 jedypjd 于 2009-10-25 13:01 编辑 ]