惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
小众软件
小众软件
Jina AI
Jina AI
The Cloudflare Blog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
G
GRAHAM CLULEY
Project Zero
Project Zero
博客园_首页
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
Latest news
Latest news
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
S
Securelist
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
IT之家
IT之家
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Last Watchdog
The Last Watchdog
T
Tenable Blog
宝玉的分享
宝玉的分享
S
Secure Thoughts
P
Privacy & Cybersecurity Law Blog
量子位
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Security Archives - TechRepublic
Security Archives - TechRepublic

博客园 - 太阳底下淋雨

amd显卡的问题 防止WindowChrome控件遮挡下面的控件 win11右键子菜单展开增加延时 [转]Git清除贡献者信息和历史提交记录,将开源项目拉取二次开发时可用到 判断是否为隐藏文件 快速查询python项目使用了哪些第三方库 C#删除路径到回收站 C#操作超长路径文件时异常的处理 win11使用传统右键菜单 Excel文件中嵌入自定义功能区customUI.xml文件后,如何进行修改 Excel中得到合并单元格的信息 WPF中文字发虚的问题解决 文件没有读取权限造成的File.Exists结果为false js如何判断当前页面是否处于激活状态 WinForm使用发布方式进行安装的安装目录 SqlServer使用row_number()分页 EF强类型查询本身部分字段时的处理 Dapper实现Like参数化 winform恢复窗口前端显示
WPF中自定义按钮实现最大化最小化动画过度效果
太阳底下淋雨 · 2024-03-27 · via 博客园 - 太阳底下淋雨

需要使用WindowsAPI

[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
private static extern int SetWindowLong32(HandleRef hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
private static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, IntPtr dwNewLong);

public IntPtr myHWND;
public const int GWL_STYLE = -16;

public static class WS
{
    public static readonly long
    WS_BORDER = 0x00800000L,
    WS_CAPTION = 0x00C00000L,
    WS_CHILD = 0x40000000L,
    WS_CHILDWINDOW = 0x40000000L,
    WS_CLIPCHILDREN = 0x02000000L,
    WS_CLIPSIBLINGS = 0x04000000L,
    WS_DISABLED = 0x08000000L,
    WS_DLGFRAME = 0x00400000L,
    WS_GROUP = 0x00020000L,
    WS_HSCROLL = 0x00100000L,
    WS_ICONIC = 0x20000000L,
    WS_MAXIMIZE = 0x01000000L,
    WS_MAXIMIZEBOX = 0x00010000L,
    WS_MINIMIZE = 0x20000000L,
    WS_MINIMIZEBOX = 0x00020000L,
    WS_OVERLAPPED = 0x00000000L,
    WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
    WS_POPUP = 0x80000000L,
    WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
    WS_SIZEBOX = 0x00040000L,
    WS_SYSMENU = 0x00080000L,
    WS_TABSTOP = 0x00010000L,
    WS_THICKFRAME = 0x00040000L,
    WS_TILED = 0x00000000L,
    WS_TILEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
    WS_VISIBLE = 0x10000000L,
    WS_VSCROLL = 0x00200000L;
}

public IntPtr SetWindowLongPtr(HandleRef hWnd, int nIndex, IntPtr dwNewLong)
{
    if (IntPtr.Size == 8)
    {
        return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
    }
    else
    {
        return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
    }
}

窗口Load事件中执行

myHWND = new WindowInteropHelper(this).Handle;
IntPtr myStyle = new IntPtr(WS.WS_CAPTION | WS.WS_CLIPCHILDREN | WS.WS_MINIMIZEBOX | WS.WS_MAXIMIZEBOX | WS.WS_SYSMENU | WS.WS_SIZEBOX);
SetWindowLongPtr(new HandleRef(null, myHWND), GWL_STYLE, myStyle);

正常调用最大化等方法就可以

this.WindowState = WindowState.Maximized;
//SystemCommands.MaximizeWindow(this);