如何使控制看起来像组合框与视觉样式启用? [英] How to render a control to look like ComboBox with Visual Styles enabled?

查看:123
本文介绍了如何使控制看起来像组合框与视觉样式启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个仿照组合框控制。我要呈现的控制,使控制的边框看起来像一个标准的的Windows组合框。具体来说,我按照MSDN文档和控制所有的渲染是正确的,除了当控制被禁用渲染。

I have a control that is modelled on a ComboBox. I want to render the control so that the control border looks like that of a standard Windows ComboBox. Specifically, I have followed the MSDN documentation and all the rendering of the control is correct except for rendering when the control is disabled.

只是要清楚,这是是视觉样式启用的系统。此外,控制各部分正确渲染除围绕残疾人边境管控,这不符合残疾人的组合框边框颜色。

Just to be clear, this is for a system with Visual Styles enabled. Also, all parts of the control render properly except the border around a disabled control, which does not match the disabled ComboBox border colour.

我现在用的是 VisualStyleRenderer 类。 MSDN建议使用 VisualStyleElement.TextBox 元素的文本框组合框的一部分控制,但标准禁用的文本框,然后一个标准的残疾组合框绘制略有不同(一个有一个浅灰色的边框,其他浅蓝色边框)。

I am using the VisualStyleRenderer class. MSDN suggests using the VisualStyleElement.TextBox element for the TextBox part of the ComboBox control but a standard disabled TextBox and a standard disabled ComboBox draw slightly differently (one has a light grey border, the other a light blue border).

我怎样才能得到控制的正确渲染处于禁用状态?

How can I get correct rendering of the control in a disabled state?

推荐答案

我不是100%肯定,如果这是你正在寻找什么,但你应该检查出的 VisualStyleRenderer 的系统。 Windows.Forms.Vi​​sualStyles命名空间。

I'm not 100% sure if this is what you are looking for but you should check out the VisualStyleRenderer in the System.Windows.Forms.VisualStyles-namespace.

  1. <一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstylerenderer.aspx"相对=nofollow> VisualStyleRenderer类(MSDN)
  2. 如何:呈现视觉样式元素(MSDN)
  3. <一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstyleelement.combobox.dropdownbutton.disabled.aspx"相对=nofollow> VisualStyleElement.ComboBox.DropDownButton.Disabled (MSDN)
  1. VisualStyleRenderer class (MSDN)
  2. How to: Render a Visual Style Element (MSDN)
  3. VisualStyleElement.ComboBox.DropDownButton.Disabled (MSDN)

由于如果用户没有启用(他/她可能正在运行经典模式或早于Windows XP的操作系统)视觉样式VisualStyleRenderer将无法正常工作,你应该始终有一个备用的ControlPaint类。

Since VisualStyleRenderer won't work if the user don't have visual styles enabled (he/she might be running 'classic mode' or an operative system prior to Windows XP) you should always have a fallback to the ControlPaint class.

// Create the renderer.
if (VisualStyleInformation.IsSupportedByOS 
    && VisualStyleInformation.IsEnabledByUser) 
{
    renderer = new VisualStyleRenderer(
        VisualStyleElement.ComboBox.DropDownButton.Disabled);
}

,然后做这样的绘图时:

and then do like this when drawing:

if(renderer != null)
{
    // Use visual style renderer.
}
else
{
    // Use ControlPaint renderer.
}

希望它能帮助!

Hope it helps!

这篇关于如何使控制看起来像组合框与视觉样式启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆