在c#里面怎样动态的画一个矩形???????????
解决方案 »
- 一道很有意思的面试题
- 多线程创建的UI不能使用输入法
- WINFORM如何实现如下功能
- 求任意三点坐标DrawArc画弧方法,急急!!!!
- 如果读取app.config的内容
- 100分问个关于网页和图片编程的问题
- 想搞个系统,大家给个思路。
- 戴志康: 一个23岁的年轻人 一名在读的大四学生 一个三年30万的程序员 一家中关村新创软件公司的CEO
- 为什么我读文件的时候没有读出汉字?
- 怎么在WIN FORM中拖曳一个按钮使其实现移动?
- 在分层结构中,我用了三层,数据访问公共部分的函数都用了static,当用户访问量大时,会不会产生并发,把数据冲掉??
- 我用c#.net写的程序,release以后是不是只能运行在装有framework的平台上?
using System.Windows.Forms;class Test : Form
{
Rectangle r = Rectangle.Empty; protected override void OnMouseDown(MouseEventArgs e)
{
r.X = e.X;
r.Y = e.Y;
} protected override void OnMouseUp(MouseEventArgs e)
{
if(e.X < r.X)
{
r.Width = r.X - e.X;
r.X = e.X;
}
else
{
r.Width = e.X - r.X;
} if(e.Y < r.Y)
{
r.Height = r.Y - e.Y;
r.Y = e.Y;
}
else
{
r.Height = e.Y - r.Y;
}
Invalidate(new Rectangle(r.X, r.Y, r.Width+1, r.Height+1));
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawRectangle(new Pen(Color.Blue, 0), r);
} static void Main()
{
Application.Run(new Test());
}
}
using System.Windows.Forms;class Test : Form
{
int x0, y0, x1, y1;
Rectangle r = Rectangle.Empty; protected override void OnMouseDown(MouseEventArgs e)
{
x0 = e.X;
y0 = e.Y;
} protected override void OnMouseMove(MouseEventArgs e)
{
x1 = e.X;
y1 = e.Y;
Invalidate();
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (x0 < x1) { r.X = x0; r.Width = x1 - x0; }
else { r.X = x1; r.Width = x0 - x1; }
if (y0 < y1) { r.Y = y0; r.Height = y1 - y0; }
else { r.Y = y1; r.Height = y0 - y1; }
e.Graphics.DrawRectangle(new Pen(Color.Blue, 0), r);
} static void Main()
{
Application.Run(new Test());
}
}