Skip to content

Instantly share code, notes, and snippets.

@stmoerman
Created October 4, 2016 19:38
Show Gist options
  • Save stmoerman/d6adf2bee467abeb7a0d3c1f3ed9d406 to your computer and use it in GitHub Desktop.
Save stmoerman/d6adf2bee467abeb7a0d3c1f3ed9d406 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
public class TransparentControl : Control
{
public TransparentControl()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.ResizeRedraw, true);
this.BackColor = Color.Transparent;
}
protected override void OnPaint(PaintEventArgs pevent)
{
Graphics g = pevent.Graphics;
g.DrawRectangle(Pens.Black, this.ClientRectangle);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// don't call the base class
//base.OnPaintBackground(pevent);
}
protected override CreateParams CreateParams
{
get
{
const int WS_EX_TRANSPARENT = 0x20;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_TRANSPARENT;
return cp;
}
}
// rest of class here...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment