如何更改禁用组合框的字体颜色? [英] How change font color of disabled combobox?

查看:88
本文介绍了如何更改禁用组合框的字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试更改已禁用组合框的字体颜色,无法找到任何解决方案。 Mabe有人知道怎么做吗?顺便说一下,我必须能够使用WndProc ...但是女巫消息?

I try change font color of disabled combobox and cant find any solution. Mabe someone know how to do this? Propably I must ovveride WndProc... but witch message?

推荐答案

到目前为止,我制作了自己的组合框,当禁用时具有白色背景(明显使用互联网:)) 。现在我需要添加代码,将字体颜色从灰色更改为黑色。



So far i made own combobox that have white back color when is disabled (using internet obviously:)). Now I need add code, that change font color from gray to black.

public partial class OwnComboBox : ComboBox
{
    [DllImport("gdi32.dll")]
    internal static extern IntPtr CreateSolidBrush(int color);

    [DllImport("gdi32.dll")]
    internal static extern int SetBkColor(IntPtr hdc, int color);

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
        IntPtr brush;
        switch (m.Msg)
        {

            case (int)312:
                SetBkColor(m.WParam, ColorTranslator.ToWin32(this.BackColor));
                brush = CreateSolidBrush(ColorTranslator.ToWin32(this.BackColor));
                m.Result = brush;

                break;
            default:
                break;
        }
    }

}


我一直在寻找有关此事的信息,以及据我所知,最好的解决方案是将组合框的DrawMode更改为OwnerDrawFixed或OwnerDrawVariable,然后在组合框的DrawItem事件中编写您自己的绘图代码。



我发现这篇文章详细介绍了它。希望它有所帮助。
I have searched around for information in the past about this, and as far as I can tell, the best solution is to change the DrawMode of the combo box to OwnerDrawFixed or OwnerDrawVariable and then write your own drawing code in the DrawItem event of the combo box.

I found this article that goes into much more detail about it. Hope it helps.


这篇关于如何更改禁用组合框的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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