c#

位置:IT落伍者 >> c# >> 浏览文章

C#窗口透明


发布日期:2020年08月23日
 
C#窗口透明

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;

}

}

}

}

               

上一篇:VS.NET安装部署深入研究

下一篇:C# 乱码解决