How to change the background color of unused space tab in C# winforms?

后端 未结 3 1796
孤街浪徒
孤街浪徒 2021-01-18 16:30

Ex

  |Tab1|Tab2|Tab3| {    }
  |                     |
  |                     |
  |                     |
  |                     |
  |____________________         


        
3条回答
  •  感动是毒
    2021-01-18 17:22

    Try adding the following code to your DrawItem event handler. Don't forget to set the DrawMode to "OwnerdrawFixed".

    You might have to tweak it a bit to cover some margins which aren't painted.

    private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
          SolidBrush fillbrush= new SolidBrush(Color.Red);

    //draw rectangle behind the tabs Rectangle lasttabrect = tabControl1.GetTabRect(tabControl1.TabPages.Count - 1); Rectangle background = new Rectangle(); background.Location = new Point(lasttabrect.Right, 0); //pad the rectangle to cover the 1 pixel line between the top of the tabpage and the start of the tabs background.Size = new Size(tabControl1.Right - background.Left, lasttabrect.Height+1); e.Graphics.FillRectangle(fillBrush, background); }

    'This answer is much better than prior one. But the tabCtrl is not defined. It has to be tabControl1 control.

提交回复
热议问题