vb.net combobox中加tooltip的问题
附上我的代码,
If e.State = DrawItemState.Selected Then e.Graphics.DrawString(CboGraphSelection.Items(e.Index).ToString(), _ CboGraphSelection.Font, SystemBrushes.HighlightText, e.Bounds) ToolTipCmb.Show(CboGraphSelection.Items(e.Index).ToString(), CboGraphSelection, _ e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height) e.DrawFocusRectangle()Else e.Graphics.DrawString(CboGraphSelection.Items(e.Index).ToString(), _ CboGraphSelection.Font, SystemBrushes.WindowText, e.Bounds) End If
Public Class Form1 Private ToolTipCmb As ToolTip Private CboGraphSelection As ComboBox Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem If e.State = DrawItemState.Selected Then e.Graphics.DrawString(CboGraphSelection.Items(e.Index).ToString(), _ CboGraphSelection.Font, SystemBrushes.HighlightText, e.Bounds) ToolTipCmb.Show(CboGraphSelection.Items(e.Index).ToString(), CboGraphSelection, _ e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height) e.DrawFocusRectangle() Else e.Graphics.DrawString(CboGraphSelection.Items(e.Index).ToString(), _ CboGraphSelection.Font, SystemBrushes.WindowText, e.Bounds) End If End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ToolTipCmb = New ToolTip CboGraphSelection = ComboBox1 End SubEnd Class