如何创建一个有边框但没有标题栏的表单? (如 Windows 7 上的音量控制)
在 Windows 7 中,音量混合器窗口具有特定的样式,具有厚而透明的边框,但没有标题栏。如何在 winforms 窗口中重新创建该窗口样式?
我尝试将 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?
I tried setting Text to string.Empty, and ControlBox to false, which removes the titlebar, but then the border also disappears:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于固定大小的窗口,您仍然应该使用
FormBorderStyle.SizableToolWindow
,但您可以重写表单的WndProc
以忽略非客户端命中测试(用于切换到调整光标大小):如果您想真正强制执行大小,您还可以在表单上将
MinimumSize
设置为等于MaximumSize
。For a fixed size window, you should still use
FormBorderStyle.SizableToolWindow
, but you can override the form'sWndProc
to ignore non-client hit tests (which are used to switch to the sizing cursors):If you want to really enforce the size, you could also set
MinimumSize
equal toMaximumSize
on the form.因为“此编辑旨在针对帖子的作者,作为编辑没有任何意义。它应该写为评论或答案。”我将对克里斯的答案进行编辑作为新答案。
他的答案的代码按描述工作 - 除了它还防止任何客户区鼠标事件发生。您需要返回 1(如 HTCLIENT 中)来解决该问题。
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.
form.FormBorderStyle = FormBorderStyle.Fixed3D;
form.FormBorderStyle = FormBorderStyle.Fixed3D;