window自带的颜色不太好看。但是tabcontrol重绘时又只有selected这个属性可以改变点击后的样式,怎么做到鼠标经过的时候也可以改变呢?
或者自定义tabcontrol怎么写?
因为程序都是全部自绘,如果用系统自带的,和系统整个颜色搭配不起来
6 个解决方案
#1
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
#2
这个treeview和tabcontrol有什么关系吗?
如果有,能不能给点具体的完整的代码
如果有,能不能给点具体的完整的代码
#3
搞错了
Private Sub TabControl_DrawItem(ByVal sender As Object, _
ByVal e As DrawItemEventArgs)
'newBaseTabCtl.Invalidate()
Dim tab As TabControl = CType(sender, TabControl)
Dim txt As String = tab.TabPages(e.Index).Text
Dim tag As String = CStr(tab.TabPages(e.Index).Tag)
Dim foreBrush, backBrush As Brush
foreBrush = Brushes.Black
backBrush = Brushes.Transparent
Dim _TabFont As Font = New Font(e.Font.FontFamily, 9.0, FontStyle.Regular, GraphicsUnit.Point)
If IsTabChanged(tab.TabPages(e.Index)) Then
foreBrush = Brushes.Red
End If
'If IstabDiff(tab.TabPages(e.Index)) Then
' backBrush = Brushes.LightBlue
'End If
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
_TabFont = New Font(e.Font.FontFamily, 8.5, FontStyle.Bold, GraphicsUnit.Point)
End If
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
e.Graphics.FillRectangle(backBrush, e.Bounds)
e.Graphics.DrawString(txt, _TabFont, foreBrush, RectangleF.op_Implicit(e.Bounds), sf)
End Sub
#4
.DrawMode = TabDrawMode.OwnerDrawFixed
AddHandler .DrawItem, AddressOf TabControl_DrawItem
'触发事件
For Each tblc As TabControl In dicGroupTabCtl(viewedSpread.Name)
tblc.Invalidate()
Next
#5
谢谢各位,搞定了
还有一个方法,获取鼠标是否在tab上,tabrect.contain(MOUSEPOSITION)就可以了
还有一个方法,获取鼠标是否在tab上,tabrect.contain(MOUSEPOSITION)就可以了
#6
学习一下自绘控件
#1
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
#2
这个treeview和tabcontrol有什么关系吗?
如果有,能不能给点具体的完整的代码
如果有,能不能给点具体的完整的代码
#3
搞错了
Private Sub TabControl_DrawItem(ByVal sender As Object, _
ByVal e As DrawItemEventArgs)
'newBaseTabCtl.Invalidate()
Dim tab As TabControl = CType(sender, TabControl)
Dim txt As String = tab.TabPages(e.Index).Text
Dim tag As String = CStr(tab.TabPages(e.Index).Tag)
Dim foreBrush, backBrush As Brush
foreBrush = Brushes.Black
backBrush = Brushes.Transparent
Dim _TabFont As Font = New Font(e.Font.FontFamily, 9.0, FontStyle.Regular, GraphicsUnit.Point)
If IsTabChanged(tab.TabPages(e.Index)) Then
foreBrush = Brushes.Red
End If
'If IstabDiff(tab.TabPages(e.Index)) Then
' backBrush = Brushes.LightBlue
'End If
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
_TabFont = New Font(e.Font.FontFamily, 8.5, FontStyle.Bold, GraphicsUnit.Point)
End If
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
e.Graphics.FillRectangle(backBrush, e.Bounds)
e.Graphics.DrawString(txt, _TabFont, foreBrush, RectangleF.op_Implicit(e.Bounds), sf)
End Sub
#4
.DrawMode = TabDrawMode.OwnerDrawFixed
AddHandler .DrawItem, AddressOf TabControl_DrawItem
'触发事件
For Each tblc As TabControl In dicGroupTabCtl(viewedSpread.Name)
tblc.Invalidate()
Next
#5
谢谢各位,搞定了
还有一个方法,获取鼠标是否在tab上,tabrect.contain(MOUSEPOSITION)就可以了
还有一个方法,获取鼠标是否在tab上,tabrect.contain(MOUSEPOSITION)就可以了
#6
学习一下自绘控件