using System;
using SystemCollectionsGeneric;
using SystemText;
using SystemRuntimeInteropServices;
namespace TransForm
{
class WinAPI
{
[DllImport(userdll)]
public extern static IntPtr GetDesktopWindow();
[DllImport(userdll)]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd uint crKey byte bAlpha uint dwFlags);
public static uint LWA_COLORKEY = x;
public static uint LWA_ALPHA = x;
[DllImport(userdll)]
public extern static uint SetWindowLong(IntPtr hwnd int nIndex uint dwNewLong);
[DllImport(userdll)]
public extern static uint GetWindowLong(IntPtr hwnd int nIndex);
public enum WindowStyle : int
{
GWL_EXSTYLE =
}
public enum ExWindowStyle : uint
{
WS_EX_LAYERED = x
}
}
}
DeviceFormcs单元是API函数的调用方式
using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
namespace TransForm
{
public partial class Form : Form
{
public Form()
{
InitializeComponent();
}
private void Form_Load(object sender EventArgs e)
{
thisSetWindowTransparent();
}
private void SetWindowTransparent(byte bAlpha)
{
try
{
WinAPISetWindowLong(thisHandle (int)WinAPIWindowStyleGWL_EXSTYLE
WinAPIGetWindowLong(thisHandle (int)WinAPIWindowStyleGWL_EXSTYLE) | (uint)WinAPIExWindowStyleWS_EX_LAYERED);
WinAPISetLayeredWindowAttributes(thisHandle bAlpha WinAPILWA_COLORKEY | WinAPILWA_ALPHA);
}
catch
{
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = baseCreateParams;
cpParent = WinAPIGetDesktopWindow();
cpExStyle = x | x;//WS_EX_TOOLWINDOW | WS_EX_TOPMOST
return cp;
}
}
}
}