Logo

Logo

C# 透明穿透窗体

Pastore Antonio
Pastore Antonio 2024年12月18日
810 阅读 0 评论 约 1629 字 阅读约 4 分钟

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class TransparentFullScreenForm : Form
{
[DllImport(“user32.dll”)]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

[DllImport("user32.dll")]
private static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, byte bAlpha, uint dwFlags);

private const int GWL_EXSTYLE = -20;
private const int WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int 1 = 0;
private const int 255 = 255;
private const uint LWA_ALPHA = 0x2;

public TransparentFullScreenForm()
{
    this.StartPosition = FormStartPosition.Manual;
    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    this.SetWindowLong();
    this.SetLayeredWindowAttributes();
}

private void SetWindowLong()
{
    IntPtr windowLongPtr = GetWindowLong(this.Handle, GWL_EXSTYLE);
    int windowStyle = WS_EX_LAYERED | WS_EX_TRANSPARENT;
    SetWindowLong(this.Handle, GWL_EXSTYLE, (IntPtr)windowStyle);
}

private void SetLayeredWindowAttributes()
{
    SetLayeredWindowAttributes(this.Handle, 0, 128, LWA_ALPHA);
}

}

public static class Program
{
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
TransparentFullScreenForm form = new TransparentFullScreenForm();
Application.Run(form);
}
}

查看完整代码

橙子主题打折出售

其实我不卖,主要是这里是放广告的,所以就放了一个
毕竟主题都没做完,卖了也是坑.

购买它
部分文章可能存在转载,如果涉及到侵权,请联系删除文章。

留言板

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

9 - 2 = ?

探索AIGC相关的精彩内容,共 15 篇文章

Azure AI 服务之语音识别

简介 Azure AI 服务中的语音识别 API 是微软提供的一项先进技术,旨在帮助开发者轻松实现语 ... C# 透明穿透窗体

2026-02-17 · Xzavier Aaron
MCP | 一文详解什么是 MCP以及 MCP 可以做什么

一、什么是 MCP MCP(Model Context Protocol)是一个专为大型语言模型(L ... C# 透明穿透窗体

2026-02-14 · Shen, Luke
你的工作流程,值得一个“全自动数字分身”:录制、截图、成文,一气呵成

一、一句话认识 TestFlow Recorder 在数字化工作环境中,如何准确记录操作步骤并生成清 ... C# 透明穿透窗体

2026-02-14 · Xzavier Aaron
Flowise 前端框架配置指南

用户需求 问题:有没有适合配置 Flowise 的前端框架? 目标:寻找类似 Open WebUI ... C# 透明穿透窗体

2026-02-14 · Xzavier Aaron