Skip to content

Instantly share code, notes, and snippets.

@sergiogarciadev
Created May 15, 2014 02:41
Show Gist options
  • Save sergiogarciadev/444c6acb48b8420f60cc to your computer and use it in GitHub Desktop.
Save sergiogarciadev/444c6acb48b8420f60cc to your computer and use it in GitHub Desktop.
A form that can't be clicked.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const int GWL_EXSTYLE = -20;
const int WS_EX_TRANSPARENT = 0x20;
[DllImport("user32.dll", CharSet=CharSet.Auto)]
extern static int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static int SetWindowLong(IntPtr hWnd, int nIndex, int nStyle);
private void Form1_Load(object sender, EventArgs e)
{
var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
var newStyle = style | WS_EX_TRANSPARENT;
SetWindowLong(this.Handle, GWL_EXSTYLE, newStyle);
}
private void timer1_Tick(object sender, EventArgs e)
{
this.BringToFront();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment