DCSIMG
Five steps for creating a transparent user control - Dotmad (on .Net)

Dotmad (on .Net)

Just Another Web 5.0 Blog

Podcasts

Blogroll

Five steps for creating a transparent user control

Guest post from Eyal Ron:
 
After much testing this is the correct formula for a truly transparent user control:
 
  1. Derive from Panel rather then UserControl.
  2.  

  3. Override the OnPaintBackground function:
  4.       protected override void OnPaintBackground(PaintEventArgs pevent)

          {

                //do nothing

          }

     

  5. Override the OnMove function:
  6.       protected override void OnMove(EventArgs e)

          {

                RecreateHandle();

          }

     

  7. Override the CreateParams property:
  8.       protected override CreateParams CreateParams

          {

                get

                {

                      CreateParams cp = base.CreateParams;

                      cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT

                      return cp;

                }

    }

     

  9. Override the OnPaint function:

      protected override void OnPaint(PaintEventArgs e)

      {

            Graphics g = e.Graphics;

 

//Do your drawing here

            .

            .

            .

     

            g.Dispose();

      }

פורסם: Nov 29 2007, 01:27 PM by Dotmad | with 3 comment(s)
תגים:

תוכן התגובה

עומר ון קלוטן כתב/ה:

When you say "truly transparent," you mean...?

# November 29, 2007 2:02 PM

אלעד כץ כתב/ה:

תעבור לWPF.. כבר שכחתי איזה חיים קשים יש

למתכנתי Winforms :)

# November 30, 2007 1:52 AM

Adi כתב/ה:

נעשים צעדים בכיוון, אבל כידוע לך זה לא תלוי רק במפתחים :)

# November 30, 2007 7:56 AM