如何在 C# 中清除屏幕区域或重绘屏幕

发布于 2024-08-17 14:04:34 字数 239 浏览 3 评论 0原文

我正在 C#.Net 2.0 中创建用户控件。 我必须在这些控件之间应用拖放图像。 我已经完成了拖放效果。

但问题是我必须在鼠标拖动时显示控件移动。 为此,我借助 ControlDraw.DrawReversibleFrame() 在屏幕上绘制一个矩形

问题是,在使用鼠标移动事件绘制时,矩形会在整个屏幕上绘制,并且由于屏幕上没有重新绘制,因此它存在于屏幕上。

所以请有人告诉我如何清除绘制的图形或如何强制重绘屏幕。

I am creating a User Control in C#.Net 2.0.
I have to apply drag and Drop Images in between these controls.
I have done drag and drop effect.

But the problem is that i have to show the control movement while mouse dragging.
For that i am drawing a rectangle on screen with the help of ControlDraw.DrawReversibleFrame()

Problem is that while drawing with mouse move event Rectangle is drawn over whole screen and because no repaint on screen it exist on screen.

So please can anybody tell me either how to clear drawn graphics or how to force to redraw screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲娇萝莉攻 2024-08-24 14:04:34

您必须在与之前相同的位置绘制“可反转”框架以将其反转,然后再在新位置绘制下一框架。

伪代码是:

bool prev_rev_frame = false;
Rect prev_rev_rect;

...

void on_mouse_move() {
  if(prev_rev_frame)
    Control.drawReversableFrame(prev_rev_rect);
  Rect new_rev_rect = ....
  Control.drawReversableFrame(new_rev_rect);
  prev_rev_frame = true;
  prev_rev_rect = new_rev_rect;
}

但一般来说,我建议将鼠标光标更改为拖放图标或图像的缩略图会更合适。

You must draw the 'reversable' frame in the same position as previously to reverse it, before drawing the next frame in the new position.

The pseudo-code is:

bool prev_rev_frame = false;
Rect prev_rev_rect;

...

void on_mouse_move() {
  if(prev_rev_frame)
    Control.drawReversableFrame(prev_rev_rect);
  Rect new_rev_rect = ....
  Control.drawReversableFrame(new_rev_rect);
  prev_rev_frame = true;
  prev_rev_rect = new_rev_rect;
}

But in general, I recommend changing the mouse cursor to a drag-drop icon or a thumbnail of the image would be far more appropriate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文