简体   繁体   English

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

[英]How to clear screen area or Redraw screen in C#

I am creating a User Control in C#.Net 2.0. 我正在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() 为此,我借助于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. 问题在于,在使用鼠标移动事件进行绘制时,Rectangle被绘制在整个屏幕上,并且由于屏幕上没有重新绘制,因此它不存在于屏幕上。

So please can anybody tell me either how to clear drawn graphics or how to force to redraw screen. 因此,任何人都可以告诉我如何清除绘制的图形或如何强制重新绘制屏幕。

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. 但通常,我建议将鼠标光标更改为拖放图标或图像的缩略图会更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM