如何创建一个有边框但没有标题栏的表单? (如 Windows 7 上的音量控制)

发布于 2024-09-16 18:03:31 字数 291 浏览 21 评论 0原文

在 Windows 7 中,音量混合器窗口具有特定的样式,具有厚而透明的边框,但没有标题栏。如何在 winforms 窗口中重新创建该窗口样式?

volumemixer

我尝试将 Text 设置为 string.Empty,将 ControlBox 设置为 false,这会删除标题栏,但也会删除边框消失:

边框消失

In Windows 7, the volume mixer windows has a specific style, with a thick, transparent border, but no title bar. How do i recreate that window style in a winforms window?

volume mixer

I tried setting Text to string.Empty, and ControlBox to false, which removes the titlebar, but then the border also disappears:

border disappears

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱的那么颓废 2024-09-23 18:03:31
form.Text = string.Empty;
form.ControlBox = false;
form.FormBorderStyle = FormBorderStyle.SizableToolWindow;

对于固定大小的窗口,您仍然应该使用 FormBorderStyle.SizableToolWindow,但您可以重写表单的 WndProc 以忽略非客户端命中测试(用于切换到调整光标大小):

protected override void WndProc(ref Message message)
{
    const int WM_NCHITTEST = 0x0084;

    if (message.Msg == WM_NCHITTEST)
        return;

    base.WndProc(ref message);
}

如果您想真正强制执行大小,您还可以在表单上将 MinimumSize 设置为等于 MaximumSize

form.Text = string.Empty;
form.ControlBox = false;
form.FormBorderStyle = FormBorderStyle.SizableToolWindow;

For a fixed size window, you should still use FormBorderStyle.SizableToolWindow, but you can override the form's WndProc to ignore non-client hit tests (which are used to switch to the sizing cursors):

protected override void WndProc(ref Message message)
{
    const int WM_NCHITTEST = 0x0084;

    if (message.Msg == WM_NCHITTEST)
        return;

    base.WndProc(ref message);
}

If you want to really enforce the size, you could also set MinimumSize equal to MaximumSize on the form.

暖树树初阳… 2024-09-23 18:03:31

因为“此编辑旨在针对帖子的作者,作为编辑没有任何意义。它应该写为评论或答案。”我将对克里斯的答案进行编辑作为新答案。

他的答案的代码按描述工作 - 除了它还防止任何客户区鼠标事件发生。您需要返回 1(如 HTCLIENT 中)来解决该问题。

protected override void WndProc(ref Message message)
{
    const int WM_NCHITTEST = 0x0084;
    const int HTCLIENT = 0x01;

    if (message.Msg == WM_NCHITTEST)
    {
        message.Result = new IntPtr(HTCLIENT);
        return;
    }

    base.WndProc(ref message);
}

Since "This edit was intended to address the author of the post and makes no sense as an edit. It should have been written as a comment or an answer." I present an edit to Chris' answer as a new answer.

The code his answer works as described - except that it also prevents any client area mouse event to occur. You need to return 1 (as in HTCLIENT) to fix that.

protected override void WndProc(ref Message message)
{
    const int WM_NCHITTEST = 0x0084;
    const int HTCLIENT = 0x01;

    if (message.Msg == WM_NCHITTEST)
    {
        message.Result = new IntPtr(HTCLIENT);
        return;
    }

    base.WndProc(ref message);
}
逆夏时光 2024-09-23 18:03:31

form.FormBorderStyle = FormBorderStyle.Fixed3D;

form.FormBorderStyle = FormBorderStyle.Fixed3D;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文