gpt4 book ai didi

c# - 当 DropDownStyle 为 DropDown 时,ComboBox Cue Banner 不是斜体

转载 作者:太空狗 更新时间:2023-10-30 00:44:02 24 4
gpt4 key购买 nike

我们有一个 WinForms 控件,它是 ComboBox 的扩展版本,在没有选择或文本时支持“提示横幅”(又名水印)。我们的控件类似于这个implementation making use of CB_SETCUEBANNER .

但是,当我们将控件的 DropDownStyle 设置为 ComboBoxStyle.DropDown(即,也允许自由文本输入)时,提示横幅显示,只是不是斜体(这是它通常显示的方式)。

有谁知道如何在 ComboBoxStyle.DropDown 模式下为组合框绘制斜体提示横幅???

最佳答案

按设计。当 Style = DropDown 时,组合框的文本部分是一个 TextBox。以非斜体样式显示提示横幅。您可以使用 this code 进行验证.当 Style = DropDownList 时,区分横幅和实际选择是很重要的,这无疑是他们选择将其显示为斜体的原因。 TextBox 的做法不同,它在获得焦点时隐藏横幅。

加入一个非精疲力尽的版本:

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);
}

关于c# - 当 DropDownStyle 为 DropDown 时,ComboBox Cue Banner 不是斜体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8904074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com