Clearing the graphics of a transparent panel C#

前端 未结 2 1866
忘掉有多难
忘掉有多难 2021-01-26 01:15

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

相关标签:
2条回答
  • 2021-01-26 01:57

    Did you try:

    graphics.Clear(Color.Transparent);
    
    0 讨论(0)
  • 2021-01-26 02:00

    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  
        }
    }
    
    0 讨论(0)
提交回复
热议问题