我有一个模仿的控件ComboBox。我想渲染该控件以便该控件border看起来像标准的Windows 组合框。具体来说,我遵循了 MSDN 文档,除了禁用控件时的渲染之外,所有控件的渲染都是正确的。
需要明确的是,这是针对具有视觉风格已启用。此外,除了禁用控件周围的边框(与禁用控件不匹配)之外,控件的所有部分都正确呈现组合框边框 colour.
我正在使用视觉风格渲染器班级。 MSDN 建议使用VisualStyleElement.TextBox
元素为TextBox的一部分ComboBox控制但标准禁用TextBox和一个标准的残疾人ComboBox绘制略有不同(一个具有浅灰色边框,另一个具有浅蓝色边框)。
如何在禁用状态下正确呈现控件?
我不能 100% 确定这是否是您正在寻找的内容,但您应该查看视觉风格渲染器在 System.Windows.Forms.VisualStyles 命名空间中。
-
VisualStyleRenderer 类 http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstylerenderer.aspx (MSDN)
-
如何:渲染视觉样式元素 http://msdn.microsoft.com/en-us/library/ms171735.aspx (MSDN)
-
VisualStyleElement.ComboBox.DropDownButton.Disabled http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstyleelement.combobox.dropdownbutton.disabled.aspx (MSDN)
由于如果用户未启用视觉样式(他/她可能运行“经典模式”或 Windows XP 之前的操作系统),VisualStyleRenderer 将无法工作,因此您应该始终回退到 ControlPaint 类。
// Create the renderer.
if (VisualStyleInformation.IsSupportedByOS
&& VisualStyleInformation.IsEnabledByUser)
{
renderer = new VisualStyleRenderer(
VisualStyleElement.ComboBox.DropDownButton.Disabled);
}
然后在绘图时这样做:
if(renderer != null)
{
// Use visual style renderer.
}
else
{
// Use ControlPaint renderer.
}
希望能帮助到你!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)