我可以使用哪些事件来通知控件它的一部分已离开屏幕的可视区域?
我有一个用户控件,我正在做一些绘画,当控件移动到屏幕边缘,或者移动到 Vista 任务栏与它重叠时,屏幕边缘/任务栏边缘被绘制到控件,留下难看的东西控件的可绘制区域上的线条。
检测此问题并在控件上调用 Invalidate 的最佳方法是什么? “Moved”和“LocationChanged”事件显然处理控件在其父容器内的移动,而不是屏幕位置的更改。 我相信当控件与 Windows XP 中的另一个窗口重叠时也会发生同样的情况,但我还没有测试过。 在这种情况下,同样的问题也适用。
我当前正在直接绘制控件的 Graphics 对象,我认为这是问题的根源。 绘制到控件的 BackGroundImage 来尝试回避这个问题会更好吗?
注意:这是对先前问题的重大改写,该问题的措辞非常糟糕。 我觉得开始一个新问题才是正确的做法,而不是试图修复我写的废话。
编辑:事实证明,任务栏并没有引起问题,只是底部屏幕边缘引起了问题。 我原以为任务栏也会引起问题,但看来我错了
I have a userControl I'm doing some Painting to, and when the control is moved to the edge of the screen, or moved so that the Vista Taskbar overlaps it, the screen edge/taskbar edge is being drawn to the control, leaving ugly lines over the paintable area of the control.
What is the best way to detect this and call Invalidate on the control? The "Moved" and "LocationChanged" events apparently deal with the movement of the control within its parent container, not with a change in screen location.
I believe the same thing will occur when the control is overlapped by another window in Windows XP, but I haven't tested that yet. Same question applies under that circumstance.
I am currently drawing directly to the control's Graphics object, which I believe is the root of the problem. Would it be better to draw to the Control's BackGroundImage as an attempt to sidestep this issue?
Note: This is a significant rephrasing of an earlier question which was phrased very badly. I felt that starting a new question was the thing to do, rather than try to repair the nonsense I had written.
EDIT: It turns out that the taskbar is not causing the problem, just the bottom screen edge. I had thought that the taskbar was causing problems as well, but it looks like I was wrong
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以绘制控件的背景,以提供无错觉问题的绘图。
您是否尝试在图形对象的剪切区域(剪切矩形)上绘制或使用其整个表面? 我认为每当另一个窗口或对象隐藏其他对象时,窗口都会向它发送重绘消息,并通过该消息传递需要重绘的区域(剪辑矩形)。
Yes you can draw control's background to give illusion problem free drawing.
Are you trying to draw on the clipped area (Clip Rectangle) of the graphics object or using whole surface of it? I think whenever another window or object hides an other object windows sends it repaint message and with that it passes the area that needs to be redrawn (clip rectangle).
在对发生的错误进行屏幕截图时,很明显问题是我正在绘制由 Paint 事件的 ClipRectangle 描述的区域,而不是由控件本身的 ClipRectangle 描述的区域。
Paint 事件的 ClipRectangle 描述了由单个 Movement 事件显示的区域,它不描述 Control 的边界区域。
我只是碰巧将控件移动得足够快,以至于很明显整个控件都被吸引到了显露的空间中。 我更改了代码以绘制到与控件大小相对应的区域,并且一切正常。
另一个 PEBKAC 问题。 哦,好吧,至少发现了错误。
While making screenshots of the error occurring, it became obvious that the problem was that I was drawing an area described by the ClipRectangle of the Paint event, and not by the ClipRectangle of the control itself.
The ClipRectangle of the Paint event describes the area that is being revealed by a single Movement event, it does not describe the area of the bounds of the Control.
I simply happened to move the control fast enough that it became obvious that the entire control was being drawn into the revealed space. I altered the code to draw to an area corresponding to the size of the control and everything worked fine.
Another PEBKAC question. Oh well, at least the error was found.