首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net combobox中加tooltip的有关问题

2012-03-31 
vb.net combobox中加tooltip的问题附上我的代码,VB codeIf e.State DrawItemState.Selected Thene.Graph

vb.net combobox中加tooltip的问题
附上我的代码,

VB code
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

这样得到的combox和原来的不一样,原来的下拉框下拉的时候,鼠标放到某一项时则替颜色是白色的,其余的是黑色的
而我用以上代码重画combobox时,不管鼠标放没放到显示的都是黑色的。
请各位高手指教

[解决办法]
用了楼主的代码,发现可以实现。有个combobox属性drawmode要变成OwnerDrawFixed

VB.NET code
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 

热点排行