Long, Karen S. (CDC/NIOSH/NPPTL) (CTR)
cyx5 at cdc.gov
Wed Apr 26 08:56:02 CDT 2006
Here is another good site, one that has a way to create custom rectangle boxes on tab controls: http://www.vb-helper.com/howto_net_ownerdraw_tab.html 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 Kath Pelletti Sent: Tuesday, April 25, 2006 8:37 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Tab Control - vb.net Karen - I have created a new Windows form, added a tab control, pasted the code inside the form's class. I am getting sytax errors on the me. lines at the top. Should these be sitting inside an event associated with the tab control? And when you say to set a reference to the tab control. do you mean via [Project], [Add Reference]? Kath ----- Original Message ----- From: Long, Karen S. (CDC/NIOSH/NPPTL) (CTR) To: Access Developers discussion and problem solving Sent: Tuesday, April 25, 2006 4:27 AM Subject: Re: [AccessD] Tab Control - vb.net 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 -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com