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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 太阳底下淋雨

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);