gpt4 book ai didi

c# - 如何从 MDI 父窗体的 MDIClient 组件中删除 3d 边框(凹陷)?

转载 作者:可可西里 更新时间:2023-11-01 08:52:43 25 4
gpt4 key购买 nike

我正在 VS2010 (.NET 4.0) 中开发 WinForms MDI 应用程序,我只是讨厌 MDI 父窗体中的 3D 边框。

关于如何移除它(使其平坦或完全没有边框)有什么想法吗?

最佳答案

我知道这是一篇旧文章,但我花了一些时间和精力从互联网上的片段中找出 3D 边框的东西(因为我也需要它),包括:

Elements from Jacob Slusser's page at codeproject.com (Accessed 1st Aug'12)

所以这里是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace MDITest
{
public static class MDIClientSupport
{
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

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

[DllImport("user32.dll", ExactSpelling = true)]
private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

private const int GWL_EXSTYLE = -20;
private const int WS_EX_CLIENTEDGE = 0x200;
private const uint SWP_NOSIZE = 0x0001;
private const uint SWP_NOMOVE = 0x0002;
private const uint SWP_NOZORDER = 0x0004;
private const uint SWP_NOREDRAW = 0x0008;
private const uint SWP_NOACTIVATE = 0x0010;
private const uint SWP_FRAMECHANGED = 0x0020;
private const uint SWP_SHOWWINDOW = 0x0040;
private const uint SWP_HIDEWINDOW = 0x0080;
private const uint SWP_NOCOPYBITS = 0x0100;
private const uint SWP_NOOWNERZORDER = 0x0200;
private const uint SWP_NOSENDCHANGING = 0x0400;

public static bool SetBevel(this Form form, bool show)
{
foreach (Control c in form.Controls)
{
MdiClient client = c as MdiClient;
if (client != null)
{
int windowLong = GetWindowLong(c.Handle, GWL_EXSTYLE);

if (show)
{
windowLong |= WS_EX_CLIENTEDGE;
}
else
{
windowLong &= ~WS_EX_CLIENTEDGE;
}

SetWindowLong(c.Handle, GWL_EXSTYLE, windowLong);

// Update the non-client area.
SetWindowPos(client.Handle, IntPtr.Zero, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);

return true;
}
}
return false;
}

}
}

在表单加载事件中调用:

form.SetBevel(false);

不要忘记更改命名空间并记住这是一个扩展方法,但它可以更改为只是另一个类或您的 MDI 父窗体中的方法调用。

关于c# - 如何从 MDI 父窗体的 MDIClient 组件中删除 3d 边框(凹陷)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7752696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com