我正在寻找一些建议...我想做的是扩展表单的客户区以包括标题栏和窗口边框。我希望能够在非客户区添加一个按钮和绘画。我读过 这篇文章,但它是用 C++ 编写的,而且我正在使用 C#(Visual Basic 也可以)。阅读后,我想出了这段代码:
public partial class Form2 : Form
{
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out Rectangle lpRect);
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y,
int cx, int cy, SetWindowPosFlags uFlags);
public enum SetWindowPosFlags : uint { };
public Form2()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0001)
{
Rectangle rcClient;
GetWindowRect(new HandleRef(this, this.Handle), out rcClient);
SetWindowPos(this.Handle, (IntPtr)0, rcClient.Left, rcClient.Top,
rcClient.Width, rcClient.Height, new SetWindowPosFlags());
//fCallDWP = true; No idea what to do with these two
//lRet = 0;
}
base.WndProc(ref m);
}
所有这一切都是使窗口更大,它对非客户区没有任何作用。我整天都在谷歌上搜索它,但没有遇到更好的东西。这件事困扰了我一段时间,所以如果有人有任何想法,请留下回复。
另外,这是我的第一篇文章,所以如果我做错了什么,请告诉我。