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?


private void addCloseButton(object sender, DrawItemEventArgs e)
{
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)
{
for (int i = 0; i < this.tabControl1.TabPages.Count; i++)
{
Rectangle r = tabControl1.GetTabRect(i);
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;
}
}
}
}
source
share