Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a quick hack (there are several things that need tweaking, but it's a start) to do the drawing of the images by hand.</p> <pre><code>Imports System.Threading Public Class MyTabControl Inherits TabControl Private tabsImages As New Concurrent.ConcurrentDictionary(Of TabPage, List(Of String)) Private tabsImagesKeys As New Concurrent.ConcurrentDictionary(Of TabPage, String) Private cycleImagesThread As Thread Private mInterval As Integer = 500 Public Sub New() Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True) Me.DrawMode = TabDrawMode.OwnerDrawFixed cycleImagesThread = New Thread(AddressOf CycleImagesLoop) cycleImagesThread.Start() End Sub Protected Overrides Sub OnHandleCreated(e As EventArgs) If Me.FindForm IsNot Nothing Then AddHandler CType(Me.FindForm, Form).FormClosing, Sub() cycleImagesThread.Abort() MyBase.OnHandleCreated(e) End Sub Private Sub CycleImagesLoop() Do Thread.Sleep(mInterval) If tabsImagesKeys.Count &gt; 0 Then For Each tabImageKey In tabsImagesKeys Dim index = tabsImages(tabImageKey.Key).IndexOf(tabImageKey.Value) index += 1 index = index Mod tabsImages(tabImageKey.Key).Count tabsImagesKeys(tabImageKey.Key) = tabsImages(tabImageKey.Key)(index) Next Me.Invalidate() End If Loop End Sub Public Property Interval As Integer Get Return mInterval End Get Set(value As Integer) mInterval = value End Set End Property Public Sub SetImages(tabPage As TabPage, images As List(Of String)) If tabsImages.ContainsKey(tabPage) Then tabsImages(tabPage) = images Else tabsImages.TryAdd(tabPage, images) End If tabsImagesKeys(tabPage) = images.First() End Sub Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs) Dim g As Graphics = e.Graphics Dim r As Rectangle = e.Bounds Dim tab As TabPage = Me.TabPages(e.Index) Dim tabImage As Image Using b = New SolidBrush(IIf(e.State = DrawItemState.Selected, Color.White, Color.FromKnownColor(KnownColor.Control))) g.FillRectangle(b, r) End Using If tabsImagesKeys.Count &gt; 0 OrElse Me.ImageList IsNot Nothing Then If tabsImagesKeys.ContainsKey(tab) Then tabImage = Me.ImageList.Images(tabsImagesKeys(tab)) g.DrawImageUnscaled(tabImage, r.X + 4, r.Y + (r.Height - tabImage.Height) / 2) End If r.X += Me.ImageList.ImageSize.Width + 4 End If Using b = New SolidBrush(tab.ForeColor) Dim textSize = g.MeasureString(tab.Text, tab.Font) g.DrawString(tab.Text, tab.Font, b, r.X, r.Y + (r.Height - textSize.Height) / 2) End Using MyBase.OnDrawItem(e) End Sub End Class </code></pre> <p>Follow these steps to setup the control:</p> <ol> <li>First of all, assign an <code>ImageList</code> control to the <code>MyTabControl</code> and fill it with images.</li> <li><p>Next, call <code>SetImages</code> method to define which images should be displayed on each tab. </p> <p>MyTabControl1.SetImages(TabPage1, New List(Of String) From {"icon.gif", "icon2.gif"}) MyTabControl1.SetImages(TabPage2, New List(Of String) From {"myImage1.gif", "myImage2.gif"})</p></li> </ol> <p>Note that the second parameter of the <code>SetImages</code> method is a list of keys which are supposed to exists on the <code>ImageList</code>. The control will do the rest...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload