Benutzer-Werkzeuge

Webseiten-Werkzeuge


windows:programming:net:code_snippsets:transparent_picturebox

Inhaltsverzeichnis

Transparente Picturebox

https://stackoverflow.com/questions/8688295/how-to-make-a-picturebox-truly-transparent
http://dotmad.blogspot.de/2007/11/five-steps-for-creating-transparent.html

After much testing this is the correct formula for a truly transparent user control:

Derive from Panel rather then UserControl.
Override the OnPaintBackground function:

protected override void OnPaintBackground(PaintEventArgs pevent){
    //do nothing
}

Override the OnMove function:

protected override void OnMove(EventArgs e){
    RecreateHandle();
}
  Override the CreateParams property:
protected override CreateParams CreateParams{
    get{
        CreateParams cp = base.CreateParams;
        cp.ExStyle = 0x00000020; //WS_EX_TRANSPARENT
        return cp;
    }
}

Override the OnPaint function:

protected override void OnPaint(PaintEventArgs e){
    Graphics g = e.Graphics;
    //Do your drawing here
    // .
    // .
    // .
    g.Dispose();
}
windows/programming/net/code_snippsets/transparent_picturebox.txt · Zuletzt geändert: 2017/11/21 14:52 von raiser