c# - Winforms - 下拉项目中的提示横幅文本框问题
问题描述
我正在尝试(出于某种原因)使用提示横幅文本框代替 WinForms 下拉项中的标准文本框。
我已将其添加到可以将新控件对象添加到下拉选项列表中的状态,但如果我这样做了,它不仅会锁定它的属性菜单,还会锁定同一下拉列表中的任何其他选项'。如果我在表单的其他地方使用它,它就没有这个问题——就在它在下拉列表中使用时。
我在下面发布了两段代码:
- 我的 CueTextBox 类(扩展 TextBox)
我的 ToolStripCueTextBox 类(从 ToolStripControlHost 派生以供设计人员使用)
**//1 - Class for box** public class CueTextBox : TextBox { private string mCue; public string Cue { get => mCue; set { mCue = value; Invalidate(); } } protected override void WndProc(ref Message m) { base.WndProc(ref m); const int WM_PAINT = 0xF; if (m.Msg == WM_PAINT) { if (!Focused && string.IsNullOrEmpty(Text) && !string.IsNullOrEmpty(Cue)) { using (var graphics = CreateGraphics()) { TextRenderer.DrawText( dc: graphics, text: Cue, font: Font, bounds: ClientRectangle, foreColor: SystemColors.GrayText, backColor: Enabled ? BackColor : SystemColors.Control, flags: TextFormatFlags.Top | TextFormatFlags.Left); } } } } **//2 - Class for toolstrip** [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All)] public class ToolStripCueTextBoxItem : ToolStripControlHost { public ToolStripCueTextBoxItem() : base(new CueTextBox()) { } }
我是新来的,但任何帮助将不胜感激!
解决方案
推荐阅读
- ios - 如何在 Charts iOS Swift 中的图标和标签之间留出空间?
- java - Hibernate Criteria API 中 Restrictions.and() 和 Restrictions.conjuction() 之间的区别
- soap - 将属性加载到基于 Weblogic 托管服务器的应用程序中
- php - Laravel 无法使用 json_decode 从 Guzzle 返回嵌套数据
- fabricjs - 如何通过在fabric.js画布中单击按钮来删除网格线
- owl-api - 解析方法OWLAPI中参数的含义(构建AST)
- python - Mysql.connector 在本地网络 Python 3 中访问远程数据库
- java - 使用 MyBatis 和 Spring 进行 Oracle 数据库轮询
- java - 如何跳过所有模块的javadoc?
- css - 谷歌字体显示在桌面但不在移动设备上(在 Android 和 iOS 上测试)