# The direction of writing from left to right

• ### Question

• I want to solve this problem
When you adjust the tab from left to right, the text appears reversed

The problem also appears in  2 when the writing changes from left to right

class tabcontrol

```Imports System.Drawing.Drawing2D

Class DotNetBarTabcontrol
Inherits TabControl
#Region " RoundRect "

Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
Dim GP As GraphicsPath = New GraphicsPath()
Dim EndArcWidth As Integer = Curve * 2
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -180, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -90, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 0, 90)
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 90, 90)
GP.AddLine(New Point(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
Return GP
End Function

Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
Dim Rectangle As Rectangle = New Rectangle(X, Y, Width, Height)
Dim GP As GraphicsPath = New GraphicsPath()
Dim EndArcWidth As Integer = Curve * 2
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -180, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -90, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 0, 90)
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 90, 90)
GP.AddLine(New Point(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
Return GP
End Function

#End Region
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(64, 64, 64)), New Rectangle(0, 0, ItemSize.Height + 4, Height))
G.DrawLine(New Pen(Color.FromArgb(40, 33, 41)), New Point(ItemSize.Height + 3, 0), New Point(ItemSize.Height + 3, 999))
For i = 1 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 xS2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.Y - 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)}
' tagpage
myBlend.Colors = {Color.FromArgb(80, 82, 79), Color.FromArgb(80, 82, 79), Color.FromArgb(80, 82, 79)}
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(40, 33, 41)), 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(103, 103, 103)), 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 + 14))

G.DrawString("" & TabPages(i).Text, Font, Brushes.White, 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.White, 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.White, 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.Regular), Brushes.DeepSkyBlue, 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(47, 47, 47)), x2)
G.DrawLine(New Pen(Color.FromArgb(40, 33, 41)), 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 + 14))
G.DrawString("" & TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
Else
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End If
Catch ex As Exception
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End Try
Else
G.DrawString(TabPages(i).Text, Font, Brushes.White, 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```

• Edited by Friday, June 29, 2018 2:11 PM
Friday, June 29, 2018 2:10 PM

### Answers

• Yes here I removed that createhandle sub and now it is working (I set the left one to left alignment and the right to right alignment). Did not change the righttoleft defaults.

Not sure about the backcolors etc.

```Imports System.Drawing.Drawing2D

Public Class Form7

End Class

Public Class DotNetBarTabcontrol
Inherits TabControl
#Region " RoundRect "

Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
Dim GP As GraphicsPath = New GraphicsPath()
Dim EndArcWidth As Integer = Curve * 2
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -180, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -90, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 0, 90)
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 90, 90)
GP.AddLine(New Point(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
Return GP
End Function

Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
Dim Rectangle As Rectangle = New Rectangle(X, Y, Width, Height)
Dim GP As GraphicsPath = New GraphicsPath()
Dim EndArcWidth As Integer = Curve * 2
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -180, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -90, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 0, 90)
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 90, 90)
GP.AddLine(New Point(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
Return GP
End Function

#End Region
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'remove this
'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 i As Integer

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(64, 64, 64)), New Rectangle(0, 0, ItemSize.Height + 4, Height))
G.DrawLine(New Pen(Color.FromArgb(40, 33, 41)), 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 xS2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.Y - 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)}
' tagpage
myBlend.Colors = {Color.FromArgb(80, 82, 79), Color.FromArgb(80, 82, 79), Color.FromArgb(80, 82, 79)}
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(40, 33, 41)), 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(103, 103, 103)), 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 + 14))

G.DrawString("" & TabPages(i).Text, Font, Brushes.White, 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.White, 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.White, 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.Regular), Brushes.DeepSkyBlue, 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(47, 47, 47)), x2)
G.DrawLine(New Pen(Color.FromArgb(40, 33, 41)), 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 + 14))
G.DrawString("" & TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
Else
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End If
Catch ex As Exception
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End Try
Else
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End If
End If
Next

e.Graphics.DrawImage(B, 0, 0)

G.Dispose() : B.Dispose()

End Sub
End Class
```

• Marked as answer by Saturday, July 7, 2018 1:03 PM
Sunday, July 1, 2018 7:03 PM
• The tabcontrol was reversed, not just writings

Did you read any of the posts from yesterday,  perhaps my first post in this thread?  I asked you the reason that you are setting the RightToLeft properties but,  you have not answered it.  I also recommended not to set those properties unless you are going to use a right to left language.  I suggested to use the Alignment property instead.  That is all you need to set unless you are using a RightToLeft language.

If you say it can`t be done then i`ll try it

• Edited by Monday, July 2, 2018 3:46 PM
• Marked as answer by Saturday, July 7, 2018 1:03 PM
Monday, July 2, 2018 3:44 PM

### All replies

• It is not clear to me exactly what the problem is or how to reproduce it.

"adjust the tab from left to right,"

Do you mean when you change the size of the tab control the text is changing? Or you set the text property to display right to left?

Can you make a simple, complete, one form example of the problem and explain exactly how to reproduce what you are describing?

We cant reproduce the problem from your example code as it is too complex and not complete.

For example what is the image list? What does RoundRect do? etc.

PS What is this supposed to do?

Try : SelectedTab.BackColor = Color.White : Catch : End Try

G.Clear(Color.White)

Is there more drawing code? Do you use ScaleTransform with a negative x axis scaling somewhere or rotation or etc?

PS Show us a picture of what the final text and image should look like. Compare to what you are now drawing.

PS What font is that you are using? Any other settings you have made for the tab etc in the designer. Do all the example setup with code. We don't know. Auto size, docking, etc.

PS There is no reason for these try catches. Remove them. This code can be debugged to work without errors.

If ImageList IsNot Nothing Then

Try

If ImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then

You don't know what your code is doing because of all the error handling that is indeterminate?

:)

PS Yes remove all that error handling. Make sure you have Visual Studio set to break on errors as shown here.

Use Option Strict On.

Sunday, July 1, 2018 9:27 AM
• I will explain the problem

The control tab   works fine

Inside the properties of the control, there is a property  to change from left to right   You have set the properties of the control to change from left to right

The tab name appears upside down incorrectly 2

I want to set the name to appear correctly 1

• Edited by Sunday, July 1, 2018 3:21 PM
Sunday, July 1, 2018 3:18 PM
• I will explain the problem

The control tab   works fine

Inside the properties of the control, there is a property  to change from left to right   You have set the properties of the control to change from left to right

The tab name appears upside down incorrectly 2

I want to set the name to appear correctly 1

I can not get my tab  control to go on the right and also have horz text like you show. How do you do that?

As far as the reversal goes it must be TabControl.RightToLeftLayout, or Control.RightToLeft or both and or your language setting?? I cant reproduce it on my system? Try combinations of those things to see what is causing the reversal or mirrored effect.

PS Mine looks like this (with .alignment = right).

Sunday, July 1, 2018 4:02 PM
• I think that the subject is not special to adjust the properties, but special drawing the line correctly and modify the times
Sunday, July 1, 2018 4:18 PM
•  Why are you setting the RightToLeft and RightToLeftLayout properties to begin with?  Are you planning to use it for right to left languages?

If you are setting those properties just to get the tabs to display on the left or right,  then you don't need to do that.  There is an Alignment Property for the TabControl that will let you align the tabs on the Left,  Top,  Right, or Bottom  without the mirroring effect.

The RightToLeft Property of all controls is meant for use with right to left languages.  Read through that link,  the Remarks section says this...

"The RightToLeft property is used for international applications where the language is written from right to left, such as Hebrew or Arabic. When this property is set to RightToLeft.Yes, control elements that include text are displayed from right to left."

The RightToLeftLayout Property is also meant for mirroring the control's layout for right to left languages too,  read the Remarks at that link too.

Here is a simple example just to show it does not mirror the text of the tabs if you set the Alignment property instead.  Requires 1 TabControl and 1 CheckBox added to the form.

```Public Class Form1    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load        TabControl1.Alignment = TabAlignment.Left        TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed        TabControl1.SizeMode = TabSizeMode.Fixed        TabControl1.ItemSize = New Size(40, 140)    End Sub    Private Sub TabControl1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles TabControl1.DrawItem        Dim tp As TabPage = TabControl1.TabPages(e.Index)        Dim TabRect As Rectangle = TabControl1.GetTabRect(e.Index)        Using sb As New SolidBrush(Color.Black)            If TabControl1.SelectedTab Is tp Then sb.Color = Color.DimGray            e.Graphics.FillRectangle(sb, TabRect)            sb.Color = If(TabControl1.SelectedTab Is tp, Color.LightSkyBlue, Color.White)            Using sf As New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}                e.Graphics.DrawString(tp.Text, e.Font, sb, TabRect, sf)            End Using        End Using    End Sub    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged        TabControl1.Alignment = If(CheckBox1.Checked, TabAlignment.Right, TabAlignment.Left)    End SubEnd Class
```

If you say it can`t be done then i`ll try it

Sunday, July 1, 2018 5:26 PM
• Hi Razerz!

I was hoping you would stop in.

"When this property is set to RightToLeft.Yes, control elements that include text are displayed from right to left."

Its not drawing right to left ie abc becomes cba... It is drawing mirrored! Correct?

PS look at the capital P in ahmed's image.

I am not sure what right to left is I need a picture to show me. :)

PS Yeah what I call mirror is not the same as the docs? The P is facing left in one side of Ahmed's image and facing Right in the other. That is not what right to left is??? That is true mirrored as in shown in a mirror? Or not?

Sunday, July 1, 2018 5:45 PM
•  Hey Tom  8)

No,  I don't think it would change  ABC into CBA,  I believe it may draw everything in reverse.  Like setting the Graphics.ScaleTransform to use a (-1) for the X scale and then using the DrawString method.  That does throw off the look of drawn text though,  if you test it.  I used X scale of -1.025 in the image below just to make the mirrored text the same length as the normally drawn text below it.

I am not to knowledgeable about the right to left stuff so,  I can't give much info on it without being wrong I'm sure.

If you say it can`t be done then i`ll try it

• Edited by Sunday, July 1, 2018 6:16 PM
Sunday, July 1, 2018 6:16 PM
•  Hey Tom  8)

No,  I don't think it would change  ABC into CBA,  I believe it may draw everything in reverse.  Like setting the Graphics.ScaleTransform to use a (-1) for the X scale and then using the DrawString method.  That does throw off the look of drawn text though,  if you test it.  I used X scale of -1.025 in the image below just to make the mirrored text the same length as the normally drawn text below it.

I am not to knowledgeable about the right to left stuff so,  I can't give much info on it without being wrong I'm sure.

If you say it can`t be done then i`ll try it

I cant get the alignment property to do anything when selected from the ide in ahmed's control.

Setting both righttoleft and righttoleftlayout will reverse the text with the ahmeds control. (as shown).

So the control is not working right. It should use the alignment and etc as Razerz said.

Again what is the proper behavior to be?

Reproducing problem Right tab has mirrored text:

Sunday, July 1, 2018 6:40 PM
• PS Ok it is in the CreateHandle sub.

```Protected Overrides Sub CreateHandle()
MyBase.CreateHandle()
Alignment = TabAlignment.Right
End Sub```

That was set to .left and for the right it needs a .right. I am not sure how to correct that to set it needs to add a variable with get and set? Razerz?

PS In fact just remove that sub? Not sure what it was supposed to do.

But here it is working on the right alignment with ahmed's control.

PS don't set  righttoleft and righttoleftlayout  to anything.

For i = 1 To TabCount - 1

'should be
For i = 0 To TabCount - 1

Sunday, July 1, 2018 6:51 PM
• Yes here I removed that createhandle sub and now it is working (I set the left one to left alignment and the right to right alignment). Did not change the righttoleft defaults.

Not sure about the backcolors etc.

```Imports System.Drawing.Drawing2D

Public Class Form7

End Class

Public Class DotNetBarTabcontrol
Inherits TabControl
#Region " RoundRect "

Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
Dim GP As GraphicsPath = New GraphicsPath()
Dim EndArcWidth As Integer = Curve * 2
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -180, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -90, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 0, 90)
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 90, 90)
GP.AddLine(New Point(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
Return GP
End Function

Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
Dim Rectangle As Rectangle = New Rectangle(X, Y, Width, Height)
Dim GP As GraphicsPath = New GraphicsPath()
Dim EndArcWidth As Integer = Curve * 2
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -180, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Y, EndArcWidth, EndArcWidth), -90, 90)
GP.AddArc(New Rectangle(Rectangle.Width - EndArcWidth + Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 0, 90)
GP.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y, EndArcWidth, EndArcWidth), 90, 90)
GP.AddLine(New Point(Rectangle.X, Rectangle.Height - EndArcWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
Return GP
End Function

#End Region
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'remove this
'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 i As Integer

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(64, 64, 64)), New Rectangle(0, 0, ItemSize.Height + 4, Height))
G.DrawLine(New Pen(Color.FromArgb(40, 33, 41)), 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 xS2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.Y - 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)}
' tagpage
myBlend.Colors = {Color.FromArgb(80, 82, 79), Color.FromArgb(80, 82, 79), Color.FromArgb(80, 82, 79)}
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(40, 33, 41)), 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(103, 103, 103)), 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 + 14))

G.DrawString("" & TabPages(i).Text, Font, Brushes.White, 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.White, 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.White, 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.Regular), Brushes.DeepSkyBlue, 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(47, 47, 47)), x2)
G.DrawLine(New Pen(Color.FromArgb(40, 33, 41)), 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 + 14))
G.DrawString("" & TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
Else
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End If
Catch ex As Exception
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End Try
Else
G.DrawString(TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End If
End If
Next

e.Graphics.DrawImage(B, 0, 0)

G.Dispose() : B.Dispose()

End Sub
End Class
```

• Marked as answer by Saturday, July 7, 2018 1:03 PM
Sunday, July 1, 2018 7:03 PM
• PS don't set  righttoleft and righttoleftlayout  to anything.

...Unless you plan on using right to left languages.  Then you might need to do some fudging of the Tab rectangle's X position.  I had to do that when setting the RightToLeft properties.  I had to set the X to the (TabControl.Width - TabRect.Width - 3) when both Right to left properties where set instead of the Alignment property.  8)

If you say it can`t be done then i`ll try it

Sunday, July 1, 2018 7:05 PM
• The tabcontrol was reversed, not just writings

Monday, July 2, 2018 9:10 AM
• The tabcontrol was reversed, not just writings

Read carefully what I said in my last post:

"I removed that createhandle sub and now it is working (I set the left one to left alignment and the right to right alignment). Did not change the righttoleft defaults."

Do you see my picture? Do you see the code? You should get the same thing. Unless it is your language setup.

The last example I posted of your code is the complete form and it is working. Paste the code into an empty form. Rebuild. Place two DotNetBarTabcontrol ontrols on a form. Set the Alignment of one to left and the other to right. Nothing else. Do not set righttoleft to anything just leave it at the defaults.

Monday, July 2, 2018 11:46 AM
• The tabcontrol was reversed, not just writings

Did you read any of the posts from yesterday,  perhaps my first post in this thread?  I asked you the reason that you are setting the RightToLeft properties but,  you have not answered it.  I also recommended not to set those properties unless you are going to use a right to left language.  I suggested to use the Alignment property instead.  That is all you need to set unless you are using a RightToLeft language.

If you say it can`t be done then i`ll try it

• Edited by Monday, July 2, 2018 3:46 PM
• Marked as answer by Saturday, July 7, 2018 1:03 PM
Monday, July 2, 2018 3:44 PM