如何设置工具提示到combobox项目@ VB.NET? [英] How to set tooltips to combobox items @ VB.NET?

查看:184
本文介绍了如何设置工具提示到combobox项目@ VB.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个给定宽度的组合框。
可能会出现一行数据被部分隐藏(组合框可能太窄)。我想通过使用工具提示或右键上下文菜单显示整行。

I have a combobox with a given width. It may occur that one row of the data is partially hidden (the combobox might be too narrow). I'd like to show the whole line by using a tooltip or right-click context menu.

目前我找不到如何'catch'行目前持有或通过鼠标。请告诉我。

Currently I can't find how to 'catch' the row that I'm currently holding on or passing over by mouse. Please tell me.

提前感谢!

推荐答案

您尝试增加 DropDownWidth 属性,可见?

Have you tried to increase the DropDownWidth property so that everything is visible?

编辑:根据列表中的项目找到理想的宽度:

To find the ideal width based on the items in the list:

var maxLength = 0;
// using the ComboBox to get a Graphics object:
using (var g = Graphics.FromHwnd(comboBox2.Handle)) {
  foreach (var item in comboBox2.Items.Cast<string>()) {
    var itemLength = g.MeasureString(item, comboBox2.Font);
    maxLength = Math.Max((int) itemLength.Width, maxLength);
  }
}
if (comboBox2.Items.Count > comboBox2.MaxDropDownItems) {
  // correction when ScrollBar is displayed
  maxLength += 15;
}
comboBox2.DropDownWidth = maxLength;

我把这个代码放在 DropDown ComboBox 进行测试。也许你可以找到一个更好的地方,例如填充 ComboBox ...

I put this code in the DropDown event of the ComboBox for testing. Maybe you can find a better place for it, like after populating the ComboBox...

这篇关于如何设置工具提示到combobox项目@ VB.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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