Tabcontrol OwnerDrawFixed from right to left in C #

I wanted to add an X button for each tab. DrawMode - OwnerDrawFixed. It works great if left to the right. As soon as I enable RightToLeftLayout = true and RightToLeft = true, it does not look very good, because it still adds the line from left to right, and this tab is added from right to left.

How to make the line also be from right to left?

enter image description here

enter image description here

private void addCloseButton(object sender, DrawItemEventArgs e)
{
    //This code will render a "x" mark at the end of the Tab caption. 
    e.Graphics.DrawString("x", e.Font, Brushes.Black, e.Bounds.Right - 15 , e.Bounds.Top +4 );
    e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left+4, e.Bounds.Top+4);
    e.DrawFocusRectangle();

}

private void actionClose(object sender, MouseEventArgs e)
{
    //Looping through the controls.
    for (int i = 0; i < this.tabControl1.TabPages.Count; i++)
    {
        Rectangle r = tabControl1.GetTabRect(i);
        //Getting the position of the "x" mark.
        Rectangle closeButton = new Rectangle(r.Right - 15, r.Top + 4, 12, 10);
        if (closeButton.Contains(e.Location))
        {
            if (MessageBox.Show("?ื”ืื ืืชื” ืจื•ืฆื” ืœืกื’ื•ืจ ื˜ืื‘ ื–ื”", "ืื™ืฉื•ืจ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.tabControl1.TabPages.RemoveAt(i);
                break;
            }
        }
    }

}
+3
source share
2 answers

Pass StringFormatwith the flag FormatFlagsset to StringFormatFlags.DirectionRightToLeft, in DrawString():

StringFormat drawFormat = new StringFormat(StringFormatFlags.DirectionRightToLeft);

var bounds = new RectangleF(.. set actual bound rectangle for text... )    

e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, bounds, drawFormat);
0
source

check here http://www.microsoft.com/middleeast/msdn/visualstudio2005.aspx you should use textrenderer instead of drawstring

-1
source

All Articles