DropDownStyleisDropDown,ComboBoxCueBannerisnotitalic它支持“cuebanners”(又名水印)。我们的控件类似于使用CB_SETCUEBANNER的此实现。但是,当我们将DropDownStyle设置为ComboBoxStyle.DropDown(即也允许自由文本输入)时,将显示提示横幅而不是斜体(通常显示方式)。有谁知道如何在ComboBoxStyle.DropDown模式下为组合框绘制斜体提示横幅?通过设计。当Style=DropDown时,combobox的文本部分为TextBox。以非斜体样式显示提示横幅。您可以使用此代码进行验证。当Style=DropDownList时,横幅和实际选择之间的差异是可见的,这无疑是他们选择斜体的原因。TextBox的做法不同,它在获得焦点时隐藏横幅。投入一个非常困倦的版本:usingSystem;使用System.Windows.Forms;使用System.Runtime.InteropServices;类CueComboBox:ComboBox{私有字符串mCue;publicstringCue{get{返回mCue;}设置{mCue=值;更新提示();}}privatevoidupdateCue(){if(this.IsHandleCreated&&mCue!=null){SendMessage(this.Handle,0x1703,(IntPtr)0,mCue);}}protectedoverridevoidOnHandleCreated(EventArgse){base.OnHandleCreated(e);更新提示();}//P/Invoke[DllImport("user32.dll",CharSet=CharSet.Unicode)]privatestaticexternIntPtrSendMessage(IntPtrhWnd,intmsg,IntPtrwp,stringlp);}C#WinForms的更简单版本:usingSystem;使用System.Runtime.InteropServices;//参考CueBannerusingSystem.Windows.Forms;命名空间Your_Project{publicpartialclassForm1:Form{privateconstintTB_SETCUEBANNER=0x1501;//文本框整数privateconstintCB_SETCUEBANNER=0x1703;//组合框整数[DllImport("user32.dll",CharSet=CharSet.Auto)]privatestaticexternInt32SendMessage(IntPtrhWnd,intmsg,intwParam,[MarshalAs(UnmanagedType.LPWStr)]stringlParam);//CueBanner的主要导入publicForm1(){InitializeComponent();SendMessage(textBox1.Handle,TB_SETCUEBANNER,0,"在这里输入...");//textBox1的提示横幅SendMessage(comboBox1.Handle,CB_SETCUEBANNER,0,"TypeHere...");//CueBannerforcomboBox1}}}之后,您可以轻松地将属性文本设为斜体,并在用户单击或键入时更改它例如:以上是C#学习教程:当DropDownStyle为DropDown时,ComboBoxCueBanner不是所有分享的内容都是斜体。如果对大家有用,需要详细了解C#学习教程,希望大家多多关注——publicForm1(){InitializeComponent();textBox1.Font=newFont(textBox1.Font,FontStyle.Italic);//textBox1的斜体字体comboBox1.Font=newFont(comboBox1.Font,FontStyle.Italic);//comboBox1的斜体字体SendMessage(textBox1.Handle,TB_SETCUEBANNER,0,"TypeHere...");//textBox1的提示横幅SendMessage(comboBox1.Handle,CB_SETCUEBANNER,0,"TypeHere...");//comboBox1的提示横幅}privatevoidtextBox1_TextChanged(objectsender,EventArgse){if(textBox1.Text!=""){textBox1.Font=newFont(textBox1.Font,FontStyle.Regular);//当用户键入时textBox1的常规字体}else{textBox1.Font=newFont(textBox1.Font,FontStyle.Italic);//ItalicFontfortextBox1whentheresnotext}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
