Как я могу изменить цвет фона (за вкладками) tabcontrol? - PullRequest
0 голосов
/ 14 апреля 2019

Я работаю над школьным проектом о железнодорожном депо, который использует TabControl, который заполняет всю форму. До сих пор я думал о таких вещах, как изменение текущего цвета вкладки или избавление от аспекта элемента управления Fixed3D, но я все еще не знаю, как изменить цвет области за вкладками, который всегда является стандартным серым цветом.

До сих пор я пытался изменить аспект элемента управления, установив для свойства DrawMode значение OwnerDrawFixed и используя код.

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
            try
            {
                //This line of code will help you to change the apperance like 
                size,name,style.
                Font f;
                //For background color
                Brush backBrush;
                //For forground color
                Brush foreBrush;
                //This construct will hell you to deside which tab page have 
                current focus
                //to change the style.
                if (e.Index == this.tabControl1.SelectedIndex)
                {
                    //This line of code will help you to change the apperance 
               like size,name,style.
                    f = new Font(e.Font, FontStyle.Bold | FontStyle.Bold);
                    f = new Font(e.Font, FontStyle.Bold);
                    backBrush = new System.Drawing.SolidBrush(Color.DimGray);
                    foreBrush = Brushes.White;
                    Graphics g = e.Graphics;
                    Pen p = new Pen(Color.DimGray, 7);
                    g.DrawRectangle(p, this.tabPage1.Bounds);
                }
                else
                {
                    f = e.Font;
                    backBrush = new SolidBrush(e.BackColor);
                    foreBrush = new SolidBrush(e.ForeColor);
                }
                //To set the alignment of the caption.
                string tabName = this.tabControl1.TabPages[e.Index].Text;
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                //Thsi will help you to fill the interior portion of
                //selected tabpage.
                e.Graphics.FillRectangle(backBrush, e.Bounds);
                Rectangle r = e.Bounds;
                r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
                e.Graphics.DrawString(tabName, f, foreBrush, r, sf);
                sf.Dispose();
                if (e.Index == this.tabControl1.SelectedIndex)
                {
                    f.Dispose();
                    backBrush.Dispose();
                }
                else
                {
                    backBrush.Dispose();
                    foreBrush.Dispose();
                }
                //set color for Background
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message.ToString(), "Error Occured", 
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

Я хочу сделать область за вкладками черной, но она останется серой, что бы я ни делал.

...