Transparent Forms in J# ( Controls NOT Transparent )

dynamic_sysop

Well-known member
Joined
Oct 1, 2002
Messages
1,039
Location
Ashby, Leicestershire.
Hi , Ive decided to build this little example on creating a Transparent Form , whilst still retaining the Colours / Visability of its Controls. But ive added a twist , its built in J# ( vs2003 is required to run this example btw )
one of the key attributes im trying to demonstrate / show people how to go about should they wish is how to use DllImport statements in J#.
eg: in C# or .NET , you would use ...
Code:
[DllImport("user32.dll")]
/// or 
<DllImport("user32.dll")> _
in J# you must use ( and the Green Highlighting is Correct for it to Work ) ...
Code:
[COLOR=Green]/** @attribute DllImport("user32.dll") */[/COLOR]
anyway the code ...
Code:
/// after the end of your Forms Class / or as a seperate Class ...
[COLOR=Blue]public class[/COLOR] _Win32
{
    [COLOR=Green]// in J# we replace the [DllImport("user32.dll")] method of C# , or <DllImport("user32.dll")> _ in .NET , with the following ( as its shown )[/COLOR]
	
    [COLOR=Green]/** @attribute DllImport("user32.dll") */[/COLOR]
    [COLOR=Blue]public static native int[/COLOR] SetLayeredWindowAttributes (IntPtr hwnd, [COLOR=Blue]int[/COLOR] crKey, [COLOR=Blue]int[/COLOR] bAlpha, [COLOR=Blue]int[/COLOR] dwFlags);
    
    [COLOR=Blue]public static int[/COLOR] WS_EX_LAYERED = 0x80000; [COLOR=Green]// this is not included in the J# runtime , as with SetLayeredWindowAttributes[/COLOR]
}
in the form that you wish to make transparent ( using its Form_Load event is best )
Code:
[COLOR=Blue]private void[/COLOR] Form1_Load (Object sender, System.EventArgs e)
{
    [COLOR=Green]// in-built Windows Calls of J#[/COLOR] 
    [COLOR=Blue]int[/COLOR] style = com.ms.win32.User32.GetWindowLong(get_Handle().ToInt32() , com.ms.win32.wing.GWL_EXSTYLE);
    style = style | _Win32.WS_EX_LAYERED;
    com.ms.win32.User32.SetWindowLong(get_Handle().ToInt32() , com.ms.win32.wing.GWL_EXSTYLE , style);
    [COLOR=Green]//[/COLOR]

[COLOR=Green]    /// unfortunatly SetLayeredWindowAttributes is not in-built to J#
    ///so i added it myself ( in the class below named _Win32)
    ///[/COLOR]

    _Win32.SetLayeredWindowAttributes(get_Handle() ,ColorTranslator.ToWin32(get_BackColor()) ,250 , 0x1 | 0x2);

}
As always ive added a zipped code project sample ...
 

Attachments

Back
Top