Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# vertical tab control with horizontal text

Tags:

c#

winforms

I want to display some information in tab control This is what I want.

I have used the methods that I found on your side to make changes in properties of tab control and using Draw Event but the output is not like what i needed.The output comes likeThis is what I am getting.. I want the text to be horizontal. Also my VS is 2008

like image 893
Vibhu Mittal Avatar asked Dec 08 '22 01:12

Vibhu Mittal


1 Answers

I followed these instructions in VB and converted them to C#. Worked for me. Basically in tab control properties set the following:

  1. Alignment = Left
  2. SizeMode = Fixed
  3. ItemSize = 30, 120: Width = 30 Height = 120
  4. DrawMode = OwnerDrawFixed

Then you have to handle DrawItem event like that:

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
    var g = e.Graphics;
    var text = this.tabControl1.TabPages[e.Index].Text;
    var sizeText = g.MeasureString(text, this.tabControl1.Font);

    var x = e.Bounds.Left + 3;
    var y = e.Bounds.Top + (e.Bounds.Height - sizeText.Height) / 2;

    g.DrawString(text, this.tabControl1.Font, Brushes.Black, x, y);
}

And the result is:

enter image description here

like image 141
PiotrWolkowski Avatar answered Dec 27 '22 06:12

PiotrWolkowski