GTK 中窗口重叠时绘制的内容丢失#
我在 GTK# 应用程序中使用 Cairo 进行绘图。当另一个窗口覆盖了部分绘制内容时,绘制内容的重叠部分就会丢失。有没有办法让它永久化?
这是我绘制内容的简化方法:
void UpdateConnectionLines ()
{
GdkWindow myWindow = GetGdkWindow();
myWindow.Clear ();
using (Context g = Gdk.CairoHelper.Create (myWindow))
{
g.Save ();
g.MoveTo (0, 20);
g.LineTo (100, 20);
g.Restore ();
g.Color = new Color (0, 0, 0);
g.LineWidth = 1;
g.Stroke();
}
}
I am using Cairo in a GTK# application for drawing. When another window covers part of the drawn content, the overlapped part of the drawn content is lost. Is there a way to make it permanent?
Here is my simplified method for drawing the content:
void UpdateConnectionLines ()
{
GdkWindow myWindow = GetGdkWindow();
myWindow.Clear ();
using (Context g = Gdk.CairoHelper.Create (myWindow))
{
g.Save ();
g.MoveTo (0, 20);
g.LineTo (100, 20);
g.Restore ();
g.Color = new Color (0, 0, 0);
g.LineWidth = 1;
g.Stroke();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您直接在窗体上绘图,那么您需要在窗体的绘制事件中执行此操作,以确保每次绘制窗体时(即当另一个窗口覆盖它然后移动时,当它调整大小时,..) .)
If you are drawing directly on the form, then you need to do it in the Form's paint event, to ensure it is there every time the form get's painted (i.e. when another window covers it and then moves, when it is resized, ...)
通过评估 John Koerner 的答案,我找到了一个适用于每个 GTK# 小部件的解决方案。我使用
genericWidgetEvent
ExposeEvent
(谢谢,ptomato)并重绘。我附加我的事件处理程序
,然后处理程序只调用我的方法:
编辑:
实际上,我没有 RTFM 正确,因为它明确指出:
Evaluating John Koerner's answer, I have found a solution, that works for every GTK# widget. I use the
genericWidgetEvent
ExposeEvent
(thanks, ptomato) and redraw.I append my event handler with
and then the handler just calls my method:
EDIT:
Actually, I have not RTFM correctly, as it explicitely states: