Awesome Custom Tab Control For VB.NET


This tab control is created by Dev Components .

the tab control looks like this.

Create a new class and add the codes and build your project then you will see the tab control in your toolbox.

Codes :
 Imports System.Drawing.Drawing2D  
 Class DotNetBarTabcontrol  
   Inherits TabControl  
   Sub New()  
     SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)  
     DoubleBuffered = True  
     SizeMode = TabSizeMode.Fixed  
     ItemSize = New Size(44, 136)  
   End Sub  
   Protected Overrides Sub CreateHandle()  
     MyBase.CreateHandle()  
     Alignment = TabAlignment.Left  
   End Sub  
   Function ToPen(ByVal color As Color) As Pen  
     Return New Pen(color)  
   End Function  
   Function ToBrush(ByVal color As Color) As Brush  
     Return New SolidBrush(color)  
   End Function  
   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)  
     Dim B As New Bitmap(Width, Height)  
     Dim G As Graphics = Graphics.FromImage(B)  
     Try : SelectedTab.BackColor = Color.White : Catch : End Try  
     G.Clear(Color.White)  
     G.FillRectangle(New SolidBrush(Color.FromArgb(246, 248, 252)), New Rectangle(0, 0, ItemSize.Height + 4, Height))  
     'G.DrawLine(New Pen(Color.FromArgb(170, 187, 204)), New Point(Width - 1, 0), New Point(Width - 1, Height - 1))  'comment out to get rid of the borders  
     'G.DrawLine(New Pen(Color.FromArgb(170, 187, 204)), New Point(ItemSize.Height + 1, 0), New Point(Width - 1, 0))          'comment out to get rid of the borders  
     'G.DrawLine(New Pen(Color.FromArgb(170, 187, 204)), New Point(ItemSize.Height + 3, Height - 1), New Point(Width - 1, Height - 1)) 'comment out to get rid of the borders  
     G.DrawLine(New Pen(Color.FromArgb(170, 187, 204)), New Point(ItemSize.Height + 3, 0), New Point(ItemSize.Height + 3, 999))  
     For i = 0 To TabCount - 1  
       If i = SelectedIndex Then  
         Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1))  
         Dim myBlend As New ColorBlend()  
         myBlend.Colors = {Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240)}  
         myBlend.Positions = {0.0F, 0.5F, 1.0F}  
         Dim lgBrush As New LinearGradientBrush(x2, Color.Black, Color.Black, 90.0F)  
         lgBrush.InterpolationColors = myBlend  
         G.FillRectangle(lgBrush, x2)  
         G.DrawRectangle(New Pen(Color.FromArgb(170, 187, 204)), x2)  
         G.SmoothingMode = SmoothingMode.HighQuality  
         Dim p() As Point = {New Point(ItemSize.Height - 3, GetTabRect(i).Location.Y + 20), New Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 14), New Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 27)}  
         G.FillPolygon(Brushes.White, p)  
         G.DrawPolygon(New Pen(Color.FromArgb(170, 187, 204)), p)  
         If ImageList IsNot Nothing Then  
           Try  
             If ImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then  
               G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 8, x2.Location.Y + 6))  
               G.DrawString("   " & TabPages(i).Text, Font, Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
             Else  
               G.DrawString(TabPages(i).Text, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
             End If  
           Catch ex As Exception  
             G.DrawString(TabPages(i).Text, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
           End Try  
         Else  
           G.DrawString(TabPages(i).Text, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
         End If  
         G.DrawLine(New Pen(Color.FromArgb(200, 200, 250)), New Point(x2.Location.X - 1, x2.Location.Y - 1), New Point(x2.Location.X, x2.Location.Y))  
         G.DrawLine(New Pen(Color.FromArgb(200, 200, 250)), New Point(x2.Location.X - 1, x2.Bottom - 1), New Point(x2.Location.X, x2.Bottom))  
       Else  
         Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width + 3, GetTabRect(i).Height + 1))  
         G.FillRectangle(New SolidBrush(Color.FromArgb(246, 248, 252)), x2)  
         G.DrawLine(New Pen(Color.FromArgb(170, 187, 204)), New Point(x2.Right, x2.Top), New Point(x2.Right, x2.Bottom))  
         If ImageList IsNot Nothing Then  
           Try  
             If ImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then  
               G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 8, x2.Location.Y + 6))  
               G.DrawString("   " & TabPages(i).Text, Font, Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
             Else  
               G.DrawString(TabPages(i).Text, Font, Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
             End If  
           Catch ex As Exception  
             G.DrawString(TabPages(i).Text, Font, Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
           End Try  
         Else  
           G.DrawString(TabPages(i).Text, Font, Brushes.DimGray, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})  
         End If  
       End If  
     Next  
     e.Graphics.DrawImage(B.Clone, 0, 0)  
     G.Dispose() : B.Dispose()  
   End Sub  
 End Class  

If you're using earlier versions of vb.net you would get errors in these lines:

myBlend.Colors = {Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232,
240), Color.FromArgb(232, 232, 240)}
myBlend.Positions = {0.0F, 0.5F, 1.0F}

an Anonymous commenter gave a solution for this, replace those two lines of code with these :
myBlend.Colors = New Color() {Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240)}
myBlend.Positions = New Single() {0.0F, 0.5F, 1.0F}

Thank You

Work from anywhere on any device with a virtual cloud desktop by CloudDesktopOnline.com . For more hosted Microsoft applications such as Exchange, SharePoint, Dynamics CRM, Project Server and more, try Apps4Rent .

47 comments

The TabPage Buttons are not Clickabel (Click -> Code window) or could anyone fix that ?
thx

Reply

it was my fault, I have this component compared with the original's all Okay!
but Thanks

greez Crusher

Reply

Hello Sir.. I got problem with this:
http://i39.tinypic.com/34q6xdh.png

How to fix it?

Reply

If you are using an older version of visual studio/visual basic .net then you would get errors sometimes.

Reply

I don't know why it's not clickable for you

Reply

This Rocks! Thanks

Reply

Thanks for this.. :-) it works ^_^

Reply

Very nice.

Thank you

Reply

I've got a problem with the two lines:

myBlend.Colors = {Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232,
240), Color.FromArgb(232, 232, 240)}
myBlend.Positions = {0.0F, 0.5F, 1.0F}

the error is "Expression Expected" on the opening brace

Reply

I think you are using an older version of vb.net, this works with vb.net 2010 or higher.

Reply

I don't know how to change this code to vb.net 2008

myBlend.Colors = {Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232,
240), Color.FromArgb(232, 232, 240)}
myBlend.Positions = {0.0F, 0.5F, 1.0F}

please help..

Reply

You cannot change this code to visual basic 2008, why not try visual basic 2010? or 2012?

Reply

Hello can we add others controls to your tabcontrol like textbox, so everytime the we add a tabpage also come with the textbox inside each tab...
Thank you!

Reply

Hello,
For that look at other themes how textboxes are added and customize this on your own. I wish I could make it for you but unfortunately I can't think of doing any activities on my computer.

Reply

hi,

how to align the tabs horizontal?

Greetings

Reply

Hey,

I think theres a property for that.

Reply

Can you do that it's adjustable?

Reply

If Option Strict On -> i have to put some extra Code:
Dim cloneBitmap As Bitmap = CType(B.Clone, Bitmap)
e.Graphics.DrawImage(cloneBitmap, 0, 0)
It works fine!

Reply

THANK YOU

Reply

Change code like below for working in earlier version of .net
myBlend.Colors = New Color() {Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240)}
myBlend.Positions = New Single() {0.0F, 0.5F, 1.0F}

Reply

Hey,

Thank you so much..! I'll update the post.

Reply

Put New Color() in front of the first curly bracket and New Size() in front of the second set.

Reply

When I run the code the form is empty. Do I need to input tab control from the toolbox to the form ? thank you =)

Reply

Thank you so much, i like this Tab Control.

Reply

i don't know to apply those codes... I created a new class and paste the code... then a new form with tab from toolbox... when I run..no changes in my tab control... please help

Reply

After adding the codes to your class, debug your project and stop. Now check your toolbox for a new tool(It's not the old tabcontrol)

Reply

I create a new form1.vb ... and then I create a new class DotNetBarTabcontrol... then I pasted the codes.... then I create tab control in my form1.vb...

Reply

Yes but not the usual tab control, check the top of the toolbox for a new tool.

Reply

can you give us download?

Reply

what will make me trust this component cause the watermark component from this site i used introduced an error into my project and i did not have a backup i had to start again

Reply

What do you mean by watermark? I don't understand what you say.

Reply
Anonymous mod

The designer could not be shown for this file because none of the classes within it can be designed. That's the error i get! Please help!

Reply

no tab page click event for this tab control? please help. TIA

Reply

working. awesome
please please please provide more free controls

Reply

Thanx works great

Reply

Very nice, thanks....

Reply

thanks very much
Pravin Savaliya

Reply

Really Nice Information,Thank You Very Much For Sharing.Web Designing Company

Reply

Very nice tab control thank you! I have one question though, how to change the color from blue to say gray or something

Reply

Ai có Project không cho mình xin đi !

Reply

Hello,

I have been using this custom tab control for some time. Very cool. I plenty of tab pages with tons of code behind each.

Recently the custom control disappeared from the toolbox and everything is gone.

Here is the error on the form main designer.

Could not find type 'WindowsApplication1.Custom_Tab_Control'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.

The Class is still there just the custom control is not in the toolbox even after compiling again.

Any advice would be greatly appreciated.

Thanks,
Russ

Reply
Anonymous mod

Why not take all of the phucking pop ups and shove where the sun dons't shine you phucking idiot

Reply

Good day sir, Sir how can i Run this code to vb ? I will copy it to a class then ?

Reply

Make a new class, delete the text in the class you created, paste the code from this example, save the project (Ctrl+Shift+S) and go to Build (in menu) and press Build. Then go to your toolbox and there will be an item named DotNetBarTabcontrol. Place it on your form like any other item

Reply

Es hora de esta replicas relojes Rolex Sky-Dweller revisión de fotos. No quería mantener a los chicos esperando demasiado tiempo para esto porque sé que los nuevos modelos de relojes Rolex réplica son siempre de gran interés desde el segundo día Rolex lanza ellos. Bueno, la paciencia es clave en este caso e incluso si sé que la paciencia es una virtud difícil aquí confía en mí es para tu propio bien.

La mejor parte es que por lo general vale la pena y si haces tu tarea bien y prestas suficiente atención acabas con una replicas rolex de buena calidad Rolex Sky-Dweller como la de mis fotos. Lo más importante es no pagar demasiado y conseguir un buen reloj Rolex falso que puede disfrutar durante mucho tiempo. Para esto usted tiene que poner algunas de las piezas del rompecabezas replicas omega juntas y emparejar la imagen final.

Reply

Post a Comment