当DropDownStyle是DropDown时,ComboBox Cue Banner不是斜体 [英] ComboBox Cue Banner not italic when DropDownStyle is DropDown

查看:163
本文介绍了当DropDownStyle是DropDown时,ComboBox Cue Banner不是斜体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个WinForms控件,它是一个扩展版本的 ComboBox ,当没有选择或文本时,它支持cue banners(aka水印)。我们的控制类似于此使用CB_SETCUEBANNER的实施

We have a WinForms control that is an extended version of ComboBox that supports "cue banners" (aka watermarks) when there is no selection or text. Our control is similar to this implementation making use of CB_SETCUEBANNER.

但是,当我们将 DropDownStyle 设置为 ComboBoxStyle.DropDown (也就是说,也允许自由文本输入)cue横幅显示,只是不是斜体(这是它通常显示)。

However, when we set DropDownStyle for the control to ComboBoxStyle.DropDown (that is, also allows free text entry) the cue banner is showing, just not in italics (which is how it usually shows).

是否有人知道如何在 ComboBoxStyle.DropDown 模式下

Does anyone know how to draw the cue banner in italics for a combo box in ComboBoxStyle.DropDown mode???

推荐答案

按设计。当Style = DropDown时,组合框的文本部分是一个TextBox。其以非斜体样式显示提示横幅。您可以使用此代码进行验证。否则重要的是,当Style = DropDownList时,使横幅和实际选择之间的区别可见,毫无疑问他们选择将其显示为斜体的原因。

By design. When the Style = DropDown, the text portion of the combobox is a TextBox. Which displays the cue banner in non-italic style. You can verify with this code. It is otherwise important to make the distinction between the banner and the actual selection visible when the Style = DropDownList, no doubt the reason they chose to display it italic. TextBox does it differently, it hides the banner when it gets the focus.

在非穷尽的版本中投入:

Throwing in a non exhausting version:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class CueComboBox : ComboBox {
    private string mCue;
    public string Cue {
        get { return mCue; }
        set {
            mCue = value;
            updateCue();
        }
    }
    private void updateCue() {
        if (this.IsHandleCreated && mCue != null) {
            SendMessage(this.Handle, 0x1703, (IntPtr)0, mCue);
        }
    }
    protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        updateCue();
    }
    // P/Invoke
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, string lp);
}

这篇关于当DropDownStyle是DropDown时,ComboBox Cue Banner不是斜体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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