|
-
Dec 1st, 2003, 12:30 PM
#1
Thread Starter
Lively Member
Tab Text Properties
This seems like a simple question, but I've been racking my brains trying to figure out how to do it.
As some of you may know from helping me before, my program adds tabpages to a tabcontrol at runtime. Certain tabpages are more important than others and my users were wondering if I could implement some kind of color-coding scheme for the text on the tab. For instance, a tab with the text "1MGH" would be red. "2TRG" and "2TCG" would be green, etc.
I can't figure out how to do this at design time, much less runtime.
I have been able to make them all bold by setting the tabcontrol font property at designtime, but if I try to play with it at runtime, it says it is a read only property.
Any ideas?
-
Dec 1st, 2003, 01:07 PM
#2
Addicted Member
Try This:
Code:
Private tabTextArea As RectangleF
Public Sub Newpage()
Dim tabControl1 As New TabControl()
Dim tabPage1 As New TabPage()
' Allows access to the DrawItem event.
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed
tabControl1.SizeMode = TabSizeMode.Fixed
tabControl1.Controls.Add(tabPage1)
tabControl1.ItemSize = New Size(80, 30)
tabControl1.Location = New Point(25, 25)
tabControl1.Size = New Size(250, 250)
tabPage1.TabIndex = 0
ClientSize = New Size(300, 300)
Controls.Add(tabControl1)
tabArea = tabControl1.GetTabRect(0)
tabTextArea = RectangleF.op_Implicit(tabControl1.GetTabRect(0))
' Binds the event handler DrawOnTab to the DrawItem event
' through the DrawItemEventHandler delegate.
AddHandler tabControl1.DrawItem, AddressOf DrawOnTab
End Sub
' Declares the event handler DrawOnTab which is a method that
' draws a string on the tabPage1 tab.
Private Sub DrawOnTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)
Dim g As Graphics = e.Graphics
Dim p As New Pen(Color.Blue)
Dim font As New Font("Arial", 10.0F)
Dim brush As New SolidBrush(Color.Red)
g.DrawString("tabPage1", font, brush, tabTextArea)
End Sub
'Add the new tab page
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Newpage()
End Sub
Got it out of the help files in VS.net
Its a starting point
Last edited by Hole-In-One; Dec 1st, 2003 at 01:24 PM.
-
Dec 1st, 2003, 01:37 PM
#3
To change a font you have to create a new font object and base it on the old one here is an example:
VB Code:
'make the current font bold
Me.Font = New Font(Me.Font, FontStyle.Bold)
Also there is no default way to change the color of the actual tab unless you do as Hole-In-One suggests and ownerdraw it. BUT the tabs have support to show icons on them. You can have different icons for the different important tabs. Just create an ImageList on the form with all the icons then assign it to the tabcontrols and at runtime set the ImageIndex property to the index of the image based on the text of the tab.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|