当DropDownStyle是DropDown时,ComboBox Cue Banner不是斜体

编程入门 行业动态 更新时间:2024-10-11 15:13:37
本文介绍了当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不是斜体

本文发布于:2023-11-06 08:48:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜体   DropDown   DropDownStyle   ComboBox   Banner

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!