|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Click passthrough on forms/controls - helpHi everyone,
I hope someone can tell me an answer to this. I want to make a form that is transparent, however, when you click it, the event does NOT fire. Instead I want the applicatoins/desktop to be clicked instead. So its basically like a dead form. I have seen this funcitonality on a Winamp plugin called Toaster. Anybody know how to do it? Thanks heaps in advance, Tim. I don't believe it's supported by the .NET Framework, but if you don't mind
doing PInvoke you can use the Windows regions APIs. using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace RegionsDemo { public partial class RegionsDemoForm : Form { [DllImport( "gdi32.dll" )] static extern IntPtr CreateRectRgn( int nLeftRect, int nTopRect, int nRightRect, int nBottomRect ); public enum CombineRgnStyles : int { RGN_AND = 1, RGN_OR = 2, RGN_XOR = 3, RGN_DIFF = 4, RGN_COPY = 5, RGN_MIN = RGN_AND, RGN_MAX = RGN_COPY } [DllImport( "gdi32.dll" )] static extern int CombineRgn( IntPtr hrgnDest, IntPtr hrgnSrc1, IntPtr hrgnSrc2, CombineRgnStyles fnCombineMode ); [DllImport( "user32.dll" )] static extern int SetWindowRgn( IntPtr hWnd, IntPtr hRgn, bool bRedraw ); [DllImport( "gdi32.dll" )] static extern bool DeleteObject( IntPtr hObject ); public RegionsDemoForm() { InitializeComponent(); AddTransparentRegion(); } private void AddTransparentRegion() { IntPtr windowRgn = CreateRectRgn( 0, 0, this.Width, this.Height ); IntPtr areaRgn = CreateRectRgn( 50, 50, 200, 200 ); IntPtr combinedRgn = CreateRectRgn( 0, 0, 0, 0 ); CombineRgn( combinedRgn, windowRgn, areaRgn, CombineRgnStyles.RGN_XOR ); SetWindowRgn( this.Handle, combinedRgn, true ); DeleteObject( combinedRgn ); DeleteObject( areaRgn ); DeleteObject( combinedRgn ); } private void Form1_Resize( object sender, EventArgs e ) { AddTransparentRegion(); } } } Hi, thanks for your reply.
However, its just not what I'm looking for. I want to be able to click on a label, and not have it be clicked. Your code is close to what I'm looking for, however, the parts you can click through are completely transparent. I only want it a little transparent. Any ideas of how to do it? Show quote "Gabriele G. Ponti" <ggponti.at.hotmail.com> wrote in message news:ebpI3%232IGHA.1760@TK2MSFTNGP10.phx.gbl... >I don't believe it's supported by the .NET Framework, but if you don't mind >doing PInvoke you can use the Windows regions APIs. > > > using System; > using System.Windows.Forms; > using System.Runtime.InteropServices; > > namespace RegionsDemo > { > public partial class RegionsDemoForm : Form > { > [DllImport( "gdi32.dll" )] > static extern IntPtr CreateRectRgn( int nLeftRect, int nTopRect, > int nRightRect, int nBottomRect ); > > public enum CombineRgnStyles : int > { > RGN_AND = 1, > RGN_OR = 2, > RGN_XOR = 3, > RGN_DIFF = 4, > RGN_COPY = 5, > RGN_MIN = RGN_AND, > RGN_MAX = RGN_COPY > } > > [DllImport( "gdi32.dll" )] > static extern int CombineRgn( IntPtr hrgnDest, IntPtr hrgnSrc1, > IntPtr hrgnSrc2, CombineRgnStyles fnCombineMode ); > > [DllImport( "user32.dll" )] > static extern int SetWindowRgn( IntPtr hWnd, IntPtr hRgn, bool > bRedraw ); > > [DllImport( "gdi32.dll" )] > static extern bool DeleteObject( IntPtr hObject ); > > public RegionsDemoForm() > { > InitializeComponent(); > AddTransparentRegion(); > } > > private void AddTransparentRegion() > { > IntPtr windowRgn = CreateRectRgn( 0, 0, this.Width, > this.Height ); > IntPtr areaRgn = CreateRectRgn( 50, 50, 200, 200 ); > IntPtr combinedRgn = CreateRectRgn( 0, 0, 0, 0 ); > > CombineRgn( combinedRgn, windowRgn, areaRgn, > CombineRgnStyles.RGN_XOR ); > > SetWindowRgn( this.Handle, combinedRgn, true ); > > DeleteObject( combinedRgn ); > DeleteObject( areaRgn ); > DeleteObject( combinedRgn ); > } > > private void Form1_Resize( object sender, EventArgs e ) > { > AddTransparentRegion(); > } > > } > } > |
|||||||||||||||||||||||