Long, Karen S. (CDC/NIOSH/NPPTL) (CTR)
cyx5 at cdc.gov
Mon Apr 24 13:27:18 CDT 2006
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Then, you need to override the OnPaint event and draw your own control.
The basic steps involved are:
Protected Overrides Function ProcessMnemonic(ByVal charCode As Char) As
Boolean
For Each p As TabPage In Me.TabPages
If Control.IsMnemonic(charCode, p.Text) Then
Me.SelectedTab = p
Me.Focus()
Return True
End If
Next p
Return False
End Function 'ProcessMnemonic
Protected Overrides Sub OnPaint(ByVal e As _
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
DrawControl(e.Graphics)
End Sub
Friend Sub DrawControl(ByVal g As Graphics)
If Not Visible Then
Return
End If
Dim render As New
VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal)
Dim TabControlArea As Rectangle = Me.ClientRectangle
Dim TabArea As Rectangle = Me.DisplayRectangle
TabArea.Y = TabArea.Y + 1
TabArea.Width = TabArea.Width + 1
Dim nDelta As Integer = SystemInformation.Border3DSize.Width
TabArea.Inflate(nDelta, nDelta)
render.DrawBackground(g, TabArea)
Dim i As Integer = 0
While i < Me.TabCount
DrawTab(g, Me.TabPages(i), i)
i += 1
End While
End Sub
Friend Sub DrawTab(ByVal g As Graphics, ByVal tabPage _
As TabPage, ByVal nIndex As Integer)
Dim recBounds As Rectangle = Me.GetTabRect(nIndex)
Dim tabTextArea As RectangleF = _
CType(Me.GetTabRect(nIndex), RectangleF)
Dim bSelected As Boolean = (Me.SelectedIndex = nIndex)
Dim render As New
VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal)
render = New
VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed)
If bSelected Then
recBounds.Height = recBounds.Height + 10
render = New
VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed)
render.DrawBackground(g, recBounds)
render.DrawEdge(g, recBounds, Edges.Diagonal, _
EdgeStyle.Sunken, EdgeEffects.Flat)
Else
recBounds.Y = recBounds.Y + 1
render = New
VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal)
render.DrawBackground(g, recBounds)
render.DrawEdge(g, recBounds, Edges.Diagonal, _
EdgeStyle.Sunken, EdgeEffects.Flat)
End If
If (tabPage.ImageIndex >= 0) AndAlso _
(Not (ImageList Is Nothing)) _
AndAlso (Not (ImageList.Images(tabPage.ImageIndex) _
Is Nothing)) Then
Dim nLeftMargin As Integer = 8
Dim nRightMargin As Integer = 2
Dim img As Image = ImageList.Images(tabPage.ImageIndex)
Dim rimage As Rectangle = New Rectangle(recBounds.X + _
nLeftMargin, recBounds.Y + 1, img.Width, img.Height)
Dim nAdj As Single = CType((nLeftMargin + _
img.Width + nRightMargin), Single)
rimage.Y += (recBounds.Height - img.Height) / 2
tabTextArea.X += nAdj
tabTextArea.Width -= nAdj
g.DrawImage(img, rimage)
End If
Dim stringFormat As StringFormat = New StringFormat
stringFormat.Alignment = StringAlignment.Center
stringFormat.LineAlignment = StringAlignment.Center
If FlagControl Then
stringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show
Else
stringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Hide
End If
Dim br As Brush
br = New SolidBrush(tabPage.ForeColor)
g.DrawString(tabPage.Text, Font, br, tabTextArea, stringFormat)
End Sub
'add a reference to the TabControl into the new project and drag the
TabControl to your form.
Karen S. Long
Programmer Analyst
EG&G Technical Services, Inc.
Pittsburgh, PA
Phone: 412-386-6649
Email: cyx5 at cdc.gov
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Dan Waters
Sent: Monday, April 24, 2006 12:35 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Tab Control - vb.net
Hi Charlotte,
I was wondering about a tab control in VB.net as well (or should this be
called VB 2005?) I depend greatly on these for my Access apps, and
wonder if the VB tab control works in a similar way as those?
Thanks!
Dan
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Charlotte
Foust
Sent: Monday, April 24, 2006 10:51 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Tab Control - vb.net
Did you ever get an answer to this? I was on vacation for 7 working
days, so I'm out of date.
Charlotte Foust
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Kath Pelletti
Sent: Wednesday, April 12, 2006 5:19 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Tab Control - vb.net
Tabs on the left with horizontal text
Kath
----- Original Message -----
From: "Charlotte Foust" <cfoust at infostatsystems.com>
To: "Access Developers discussion and problem solving"
<accessd at databaseadvisors.com>
Sent: Thursday, April 13, 2006 10:15 AM
Subject: Re: [AccessD] Tab Control - vb.net
> Text on labels is normally horizontal. Do you have the tabs on the
> side, or did you mean vertical text?
>
>
> Charlotte Foust
>
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Kath
Pelletti
> Sent: Wednesday, April 12, 2006 5:04 PM
> To: AccessD VB List; Access D Normal List
> Subject: [AccessD] Tab Control - vb.net
>
> (Cross posted to accessd normal and vb.net lists)
>
> I am trying to create a form in vb.net with a tab control, where the
> text on the labels is shown horizontally. If you look at [View],
> [Property Pages] in vb.net to see the properties of the vb.net app
then
> they display a tab control exactly like what I need......
>
> Does anyone know which properties I set to get the text to go that
way?
> I can't find it....
>
> ______________________________________
> Kath Pelletti
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com