Tipp 0078 TabControl - Farbige Einträge und Grafiken
Autor/Einsender:
Datum:
  Klaus D. Raudszus
28.05.2005
Entwicklungsumgebung:   VB.Net 2003
Framework:   1.1
Mit Hilfe einer abgeleiteten Klasse des TabControls (Inherits) können farbige Einträge und Bilddarstellungen in den Registerlaschen des TabControls erreicht werden.
Code in uTabControl
 
Imports System.IO

Public Class uTabControl
  Inherits TabControl

  Private m_ImageItems() As String

  Public Sub New()
    DrawMode = TabDrawMode.OwnerDrawFixed
    m_ImageItems = Directory.GetFiles("..\Bilder", "*.bmp")
  End Sub

  Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
    Dim strText As String = CStr(TabPages.Item(e.Index).Text)
    Dim brBrush As Brush
    If CBool(e.State And DrawItemState.Selected) Then
      brBrush = New SolidBrush(Color.LightBlue)
    Else
      brBrush = New SolidBrush(Color.LightGreen)
    End If
    e.Graphics.FillRectangle(brBrush, e.Bounds)
    brBrush = New SolidBrush(Color.Black)
    e.Graphics.DrawString(strText, e.Font, brBrush, _
          e.Bounds.Left + 2, e.Bounds.Top + 2)
    Dim newImage As Bitmap = New Bitmap(m_ImageItems(e.Index))
    e.Graphics.DrawImage(newImage, e.Bounds.Left, _
          e.Bounds.Top + 1, 24, e.Bounds.Height - 2)
  End Sub
End Class
 
Code in frmMain
 
Public Class frmMain
  Inherits System.Windows.Forms.Form

#Region " Vom Windows Form Designer generierter Code "

  Friend WithEvents uTC As uTabControl
  Friend WithEvents TP1 As TabPage
  Friend WithEvents TP2 As TabPage
  Friend WithEvents TP3 As TabPage
  Friend WithEvents TP4 As TabPage
  Friend WithEvents TP5 As TabPage
  Friend WithEvents TP6 As TabPage

  Public Sub New()
    MyBase.New()
    InitializeComponent()

    uTC = New uTabControl()
    uTC.Width = 400
    Controls.Add(uTC)
    TP1 = New TabPage()
    TP1.Text = ".       Deutschland"
    TP1.BackColor = Color.Beige
    TP2 = New TabPage()
    TP2.Text = ".       Dänemark"
    TP3 = New TabPage()
    TP3.Text = ".       Finnland"
    TP4 = New TabPage()
    TP4.Text = ".       Frankreich"
    TP5 = New TabPage()
    TP5.Text = ".       Italien"
    TP6 = New TabPage()
    TP6.Text = ".       Rußland"
    uTC.Controls.Add(TP1)
    uTC.Controls.Add(TP2)
    uTC.Controls.Add(TP3)
    uTC.Controls.Add(TP4)
    uTC.Controls.Add(TP5)
    uTC.Controls.Add(TP6)
  End Sub

  '...
#End Region

  Private Sub Button1_Click(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles Button1.Click
    Me.Close()
  End Sub
End Class
 
Links zum Thema
Farbige ListBox und Bilder einfügen
Datagrid-Spalten farbig unterlegen

Windows-Version
98/SE
ME
NT
2000
XP
Vista
Win 7


Download  (8,8 kB) Downloads bisher: [ 606 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Tipps | Projekte | Tutorials | Bücherecke | VB-/VBA-Tipps | API-Referenz | Komponenten | VB.Net-Forum | VB/VBA-Forum | DirectX-Forum | Foren-Archiv | DirectX | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Samstag, 21. Januar 2012