gpt4 book ai didi

vb.net - 如何为组合框中的每个项目添加工具提示

转载 作者:行者123 更新时间:2023-12-03 05:56:09 26 4
gpt4 key购买 nike

我搜索了各种解决方案,但没有一个给我直接答案,或者不是用 vb.net 编写的。但我的情况是,我有一个 ComboBox,其中有一些用户可以选择的项目。我想添加简单的工具提示,以便每个用户都知道他或她正在选择什么。但是,在选择某个项目之前,工具提示不会显示。我希望当鼠标悬停在每个项目上时显示工具提示。

下面是我的代码:

Private Sub VotingAgentComboBox_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VotingAgentComboBox.MouseHover
Dim VotingAgentToolTip As New ToolTip
If VotingAgentComboBox.Text = "ISS" Then VotingAgentToolTip.SetToolTip(VotingAgentComboBox, "You selected ISS")
End Sub

最佳答案

试试这个..将工具提示控件添加到您的窗体中,并将​​此代码写入到组合框控件的 DrawItem 事件

组合框的drawmode属性设置为OwnerDrawFixed

if (e.Index == -1) { return; }

Point p = new Point(ComboBox1.Location.X + 120, ComboBox1.Location.Y + ComboBox1.Height + (30 + e.Index * 10));



if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{

toolTip.Show(ComboBox1.Items[e.Index].ToString(), this, p);

}



e.DrawBackground();

e.Graphics.DrawString(ComboBox1.Items[e.Index].ToString(), e.Font, Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y));

关于vb.net - 如何为组合框中的每个项目添加工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21859629/

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