当前位置: 代码迷 >> VB Dotnet >> tabcontrol 鼠标经过 背景色改变,该怎么处理
  详细解决方案

tabcontrol 鼠标经过 背景色改变,该怎么处理

热度:438   发布时间:2016-04-25 02:23:59.0
tabcontrol 鼠标经过 背景色改变
如果做到tabcontrol在鼠标经过时,背景色有变化,点击后,背景色又是另外的。
window自带的颜色不太好看。但是tabcontrol重绘时又只有selected这个属性可以改变点击后的样式,怎么做到鼠标经过的时候也可以改变呢?
或者自定义tabcontrol怎么写?
因为程序都是全部自绘,如果用系统自带的,和系统整个颜色搭配不起来
------解决方案--------------------

Private Sub treeView_DrawNode(ByVal sender As Object, ByVal e As DrawTreeNodeEventArgs)
        Dim f As Font = If(e.Node.NodeFont IsNot Nothing, e.Node.NodeFont, e.Node.TreeView.Font)

        Dim fore As Color = e.Node.ForeColor
        'If fore = Color.Empty Then
        '    fore = e.Node.TreeView.ForeColor
        'End If
       If IsTreeNodeChanged(e.Node) Then
            fore = Color.Red
        End If
        ' Have to indicate focus somehow, how about yellow foreground text?
        If e.Node Is e.Node.TreeView.SelectedNode Then
            'fore = SystemColors.HighlightText
            If (e.State And TreeNodeStates.Focused) <> 0 Then
                f = New Font("Meiryo UI", 9.0!, FontStyle.Bold)
            End If
        End If
        Dim sz As Size = TextRenderer.MeasureText(e.Node.Text, New Font("Meiryo UI", 9.0!, FontStyle.Bold))
        Dim rc As New Rectangle(e.Bounds.X - 1, e.Bounds.Y, sz.Width + 2, e.Bounds.Height)

        Dim back As Color = e.Node.BackColor
        'If IsTreeNodeDiff(e.Node) Then
        '    back = Color.LightBlue

        'Else
        If back = Color.Empty Then
            back = e.Node.TreeView.BackColor
        End If
        If e.Node Is e.Node.TreeView.SelectedNode Then
            back = Color.FromArgb(255, 51, 153, 255)

        End If
        'End If
        Dim bbr As New SolidBrush(back)
        e.Graphics.FillRectangle(bbr, rc)
        TextRenderer.DrawText(e.Graphics, e.Node.Text, f, rc, fore, TextFormatFlags.GlyphOverhangPadding)
        bbr.Dispose()
        f.Dispose()
    End Sub
.DrawMode = TabDrawMode.OwnerDrawFixed
AddHandler .DrawItem, AddressOf TabControl_DrawItem