c# - 如何使用视觉样式绘制 3D 边框?

标签 c# .net winforms visual-styles

我可以使用 ControlPaint.DrawBorder3D 绘制 3D 边框,但我得到的是“Windows 经典”3D 边框。我想绘制当前主题的 3D 边框——在默认的 XP 主题中,这是一个 1px 的蓝色或灰色边框。我如何绘制它,如何获得它的宽度?

最佳答案

听起来您可能需要查看 System.Windows.Forms.VisualStyles.VisualStyleRenderer :

The System.Windows.Forms.VisualStyles namespace exposes VisualStyleElement objects that represent all of the controls and user interface (UI) elements that are supported by visual styles. To draw or get information about a particular element, you must set a VisualStyleRenderer to the element you are interested in.

To draw an element, use the DrawBackground method. The VisualStyleRenderer class also includes methods, such as GetColor and GetEnumValue, that provide information about how an element is defined by the current visual style.

该页面上还有一个代码示例。

您必须自己绘制边框,但您可以从 VisualStyleElement.Window.Caption.Active 获取颜色,并且尺寸应该是窗框的尺寸(我相信),这是 VisualStyleElement.Window.FrameBottom.Active。如果您探索 VisualStyleElement.Window,您应该能够确定哪个窗口元素具有绘制边框所需的信息。

关于c# - 如何使用视觉样式绘制 3D 边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/569289/

相关文章:

c# - 您可以使用多个过滤器调用 Directory.GetFiles() 吗?

c# - 如何在不使最后一行空白的情况下向富文本框添加新行?

.net - 创建 .NET 组件,例如 Windows 搜索工具栏

c# - 如何使用 C# 为我的 WinRT 应用程序生成 MD5 哈希码?

c# - MVC4 种子数据库外键 ID

c# - Unity 生成的对象不会向前旋转

c# - 如何使用 MS Graph 将 Azure 门户注册应用程序的范围限制为只能访问 sharepoint 中的特定日历

c# - 如何防止 .NET 的 XmlDocument 输出中的空白 xmlns 属性?

c# - 免版税和免费音效

c# - 具有任意列数的可绑定(bind)数据源