flash a tab control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, this will seem like an odd question but il explain. im making an AIM
Custom Client with the SDK they released. I want to add tabbed IMs using a
tab control. I made a custom control inheriting the tab page, but im
wondering if i can flash a tab page like i can flash a window. Just have it
flash until it gets focus, like a window once again. is this possible?
 
Not a standard feature, but you could do it by OwnerDrawing. Just set off a
timer to paint the tab in alternating colors. You will lose the VisualStyle
of the TabControl though.

A simple example:

Private flashTab As Boolean
Private TabToFlash As New ArrayList
Private WithEvents FlashTimer As New Timer

Private Sub TabControl1_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles TabControl1.DrawItem

Dim backBrush As New SolidBrush(SystemColors.Control)
Dim tabRect As RectangleF = _
RectangleF.op_Implicit(Me.TabControl1.GetTabRect(e.Index))
Dim tp As TabPage = Me.TabControl1.TabPages(e.Index)
If tp Is Me.TabControl1.SelectedTab Then
tabRect.Inflate(2, 2)
End If

If FlashTimer.Enabled Then
If TabToFlash.Contains(tp) AndAlso flashTab Then
backBrush.Color = Color.Orange
End If
End If

e.Graphics.FillRectangle(backBrush, tabRect)

Dim sf As New StringFormat(StringFormatFlags.NoWrap)
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
backBrush.Color = SystemColors.ControlText
e.Graphics.DrawString(tp.Text, e.Font, backBrush, tabRect, sf)
backBrush.Dispose()
sf.Dispose()

End Sub

Private Sub FlashTimer_Tick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles FlashTimer.Tick
flashTab = Not flashTab
TabControl1.Invalidate()
End Sub

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles TabControl1.SelectedIndexChanged
If TabToFlash.Contains(TabControl1.SelectedTab) Then
TabToFlash.Remove(TabControl1.SelectedTab)
If TabToFlash.Count = 0 Then
FlashTimer.Stop()
End If
TabControl1.Invalidate()
End If
End Sub

'Example Usage
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Static r As New Random
Dim tp As TabPage = TabControl1.TabPages(r.Next(TabControl1.TabCount))
If Not (TabToFlash.Contains(tp)) AndAlso _
Not (tp Is TabControl1.SelectedTab) Then
TabToFlash.Add(tp)
Else
Return
End If
FlashTimer.Interval = 400
FlashTimer.Start()
End Sub
 
just letting anyone whos interested know, that changing the back color of the
control does not change the title of the tab control like i hoped, so i used
an ImageList instead to change an image when i need to get the users
attention. just FYI
 
Back
Top