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();
}
}
}
Timothy - 28 Jan 2006 01:44 GMT
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?
>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.
[quoted text clipped - 63 lines]
> }
> }