为了避免在我的code闪烁我的、为了避免、code

由网友(少年范儿,))分享简介:我M在C#中绘制矩形鼠标移动,I m drawing rectangle on mouse move in c#,我写了code这个样子,i wrote the code like this,Rectangle rect = new Rectangle(Math.Min(mouseMovePoint.X, mo...

我M在C#中绘制矩形鼠标移动,

I m drawing rectangle on mouse move in c#,

我写了code这个样子,

i wrote the code like this,

Rectangle rect = new Rectangle(
    Math.Min(mouseMovePoint.X, mouseDownPoint.X), 
    Math.Min(mouseMovePoint.Y, mouseDownPoint.Y),
    Math.Abs(mouseMovePoint.X - mouseDownPoint.X), 
    Math.Abs(mouseMovePoint.Y - mouseDownPoint.Y)
);

    graphics.DrawRectangle(myPen, rect);

onmouseup:

this.Refresh();

Rectangle rect = new Rectangle(
    Math.Min(mouseMovePoint.X, mouseDownPoint.X), 
    Math.Min(mouseMovePoint.Y, mouseDownPoint.Y),
    Math.Abs(mouseMovePoint.X - mouseDownPoint.X), 
    Math.Abs(mouseMovePoint.Y - mouseDownPoint.Y)
);

graphics.DrawRectangle(myPen, rect);

但由于此刷新方法时,我画它看起来像,就好像它那闪烁的矩形如何避免呢?

But due to this refresh method when i draw the rectangle it appears like as if it s flickering how to avoid that?

推荐答案

使用 ControlPaint.DrawReversibleFrame 用于绘制选择框,中联的MouseDown 的MouseMove 的MouseUp 事件。检查这个 MSDN上。

Use ControlPaint.DrawReversibleFrame for drawing selection boxes, in conjunction with MouseDown, MouseMove and MouseUp events. Check this on MSDN.

阅读全文

相关推荐

最新文章