如何控制 Windows 窗体上的边框粗细和颜色?

发布于 2024-07-29 23:42:32 字数 138 浏览 2 评论 0原文

我知道这可以在系统级别进行控制,但我想覆盖系统设置并仅对我的应用程序具有特定的外观。 我假设必须有一个 Windows API 函数来控制它,因为我见过另一个 Windows 应用程序可以做到这一点。

(没有必要深究我不应该这样做的原因)

I know that this can be controlled at the system level, but I want to override the system setting and have a certain appearance for only my application. I'm assuming there must be a Windows API function to control this because I've seen another windows app that does it.

(It is not necessary to go into the reasons why I should not do this)

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

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

发布评论

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

评论(2

满地尘埃落定 2024-08-05 23:42:35

应用程序窗口的这些外部元素统称为窗口“镶边”,并且实际上由操作系统呈现。 在 Windows API 级别使用各种标志来控制每个窗口实例的某些方面(例如,控制框、边框、最小/最大按钮等的存在),但可调整大小的窗口的边框宽度由系统设置确定以确保一致性,并且不可逐个窗口进行配置。

在许多情况下,您可以通过与 Windows API 交互来控制 .NET 未公开的窗口的某些方面,并且阅读 Windows API 文档以确定在较低级别上可能发生的情况是有益的。 我建议阅读 CreateWindowEx 的文档作为起点。

http://msdn.microsoft.com/en-us /library/ms632680(VS.85).aspx

.NET 允许您更改 FormBorderStyle 属性以在无边框、单像素宽度边框和可调整大小(粗边框)之间进行选择。 如果您想要进行自定义操作,则必须将 .NET 边框样式设置为 none,然后自行负责渲染窗口镶边。 这需要渲染您自己的标题栏、最小/最大按钮和窗口边框。 这不是一件容易的事,但许多应用程序都可以做到这一点。 如果您真正想要的只是控制边框宽度,那么还有很长的路要走。

本文探讨如何在 WPF 中完成此任务,并且也可能有用。

WPF 中的 Chrome 窗口

These outer elements of an applications window are collectively referred to as the windows "chrome" and are indeed rendered by the operating system. Various flags are used at the windows API level to controls certain aspects of each window instance (e.g. the existing of a control box, border, min/max buttons, etc.), but the border width for resizable windows is determined by a system setting to ensure uniformity and is not configurable on a window by window basis.

You can, in many instances, gain control over some of the aspects of your window not exposed by .NET by interacting with the windows API and it is beneficial to read the windows API documentation to determine just what is possible at that lower level. I suggest reading the documentation for CreateWindowEx as a starting point.

http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

.NET allows you to change the FormBorderStyle property to select among no border, single pixel width border, and resizable (thick border). If you'd like to do something custom, you'll have to set the .NET border style to none, and then assume the responsibility for rendering the window chrome yourself. This entails rendering your own caption bar, min/max buttons, and window border. It's not a light undertaking, but many apps do it. It's a long way to go if all you really want is to control the border width.

This article goes into how one might approach this task in WPF, and may also be of use.

Window Chrome In WPF

两相知 2024-08-05 23:42:34

如果您想要为应用程序提供自定义外观,我只需使表单无边框并自己处理所有内容,方法是在 Paint 事件中在表单本身上绘图,或者在 Resize 事件中移动控件(面板等)。 您必须处理诸如拖动、调整大小、关闭/最小化等操作,但这些都不是特别困难。

这是我对类似问题的回答 ,它展示了自己动手的基础知识(它适用于 Windows Mobile,但也可以在常规 Windows 中使用)。

If you want a custom appearance for your application, I would just make my form borderless and handle everything myself, either by drawing on the form itself in the Paint event, or else moving controls around (panels etc.) in the Resize event. You have to handle things like dragging, resizing, closing/minimizing etc., but none of this is especially difficult.

Here is my answer to a similar question, which shows the basics of doing it yourself (it's for windows mobile, but it will work in regular windows too).

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