0

我有一个 WebBrowser 控件,顶部有一个透明面板,我想做的是在透明面板上围绕鼠标悬停的页面中的元素绘制一个矩形。

到目前为止,除了在绘制下一个矩形之前没有清除面板之外,我已经完成了所有工作,所以我最终到处都是矩形。

这是我使用的代码。

paneGraphics = drawingPane.CreateGraphics();

Rectangle inspectorRectangle;

inspectorRectangle = controller.inspectElement();

paneGraphics.DrawRectangle(new Pen(Color.Blue, 1), inspectorRectangle);     

drawingPane.Invalidate();

我试过使用 drawingPane.clear() 但这只会把屏幕变白。

4

2 回答 2

2

看看 OpenPandora 项目的代码

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  
    }
}
于 2010-05-21T17:41:36.933 回答
0

你试过了吗:

graphics.Clear(Color.Transparent);
于 2009-04-28T17:39:22.620 回答