我可以使用 ControlPaint.DrawBorder3D 绘制 3D 边框,但我得到的是“Windows 经典”3D 边框。我想绘制当前主题的 3D 边框——在默认的 XP 主题中,这是一个 1px 的蓝色或灰色边框。我如何绘制它,如何获得它的宽度?
最佳答案
听起来您可能需要查看 System.Windows.Forms.VisualStyles.VisualStyleRenderer :
The
System.Windows.Forms.VisualStyles
namespace exposesVisualStyleElement
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 aVisualStyleRenderer
to the element you are interested in.To draw an element, use the
DrawBackground
method. TheVisualStyleRenderer
class also includes methods, such asGetColor
andGetEnumValue
, 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/