清除的透明面板C#图形 [英] Clearing the graphics of a transparent panel C#
本文介绍了清除的透明面板C#图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有过它的顶部的透明面板WebBrowser控件,我所要做的是画一个矩形页面元素周围的透明面板鼠标悬停在
I have a WebBrowser control with a transparent panel over the top of it, what I am trying to do is draw a rectangle on the transparent panel around the element in the page that the mouse is hovering over.
到目前为止,我有除外面板一切工作画下一个矩形,这样我结束了无处不在的矩形之前没有被清除。
So far I have everything working except the panel is not being cleared before drawing the next rectangle so I end up with rectangles everywhere.
继承人代码即时通讯使用
heres the code Im using.
paneGraphics = drawingPane.CreateGraphics();
Rectangle inspectorRectangle;
inspectorRectangle = controller.inspectElement();
paneGraphics.DrawRectangle(new Pen(Color.Blue, 1), inspectorRectangle);
drawingPane.Invalidate();
我使用drawingPane.clear(尝试),但偏偏在屏幕的白色。
I've tried using drawingPane.clear() but that just turns the screen white.
推荐答案
看看在OpenPandora项目的代码
Take a look at the OpenPandora project's code
public class TransparentPanel : Panel
{
Timer Wriggler = new Timer();
public TransparentPanel()
{
Wriggler.Tick += new EventHandler(TickHandler);
this.Wriggler.Interval = 500;
this.Wriggler.Enabled = true;
}
protected void TickHandler(object sender, EventArgs e)
{
this.InvalidateEx();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected void InvalidateEx()
{
if (Parent == null)
{
return;
}
Rectangle rc = new Rectangle(this.Location, this.Size);
Parent.Invalidate(rc, true);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// Do not allow the background to be painted
}
}
这篇关于清除的透明面板C#图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文