رسم یک Rectangle با ماوس راحته اما یک مشکلی بعضی مواقع پیش می یاد(حد اقل برای من) که وقتی می خوایم یک مستطیل رو به طرف بالا رسم کنیم رسم نمیشه و حالا..
این یه خلاصه.
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 WindowsFormsApplication19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Point startPos;
Point currentPos;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
startPos = startPos = e.Location;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
currentPos = e.Location;
this.Invalidate();
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(Color.Red), Math.Min(startPos.X, currentPos.X), Math.Min(startPos.Y, currentPos.Y), Math.Abs(startPos.X - currentPos.X), Math.Abs(startPos.Y - currentPos.Y));
}
}
}
اینم نمونه کد اصلی که من دیدم
http://stackoverflow.com/questions/4...usedown-move-c





پاسخ با نقل قول
