Home > Enterprise >  My tabControl1 wont show its DrawImage after I added custom backcolor to my tabControl1
My tabControl1 wont show its DrawImage after I added custom backcolor to my tabControl1

Time:05-12

I am not really sure where I am going wrong but before I added my custom backcolor to my tabControl1 everything worked fine, I saw the X on other tabs and the to add tabs

enter image description here

After I added this source of code my Tabs I add are not there but the button functions and going on other tabs functions aswell making me think that the backColor is just hiding them behind.

            SolidBrush backColor = new SolidBrush(Color.FromArgb(40, 40, 40)); // change back color
            e.Graphics.FillRectangle(backColor, rec);

enter image description here

Is there like any way that the Tab Pages display fully with the DrawItems I have put in with the backColor?

The code source:

        private void tabControl1_DrawItem_1(object sender, DrawItemEventArgs e)
        {
            Rectangle rec = tabControl1.ClientRectangle;

            SolidBrush backColor = new SolidBrush(Color.FromArgb(40, 40, 40)); // change back color
            e.Graphics.FillRectangle(backColor, rec);

            StringFormat StrFormat = new StringFormat();
            StrFormat.LineAlignment = StringAlignment.Center;
            StrFormat.Alignment = StringAlignment.Center;

            Brush bshBack = new SolidBrush(Color.FromArgb(55, 55, 55)); // change tab color

            var tabPage = this.tabControl1.TabPages[e.Index];
            var tabRect = this.tabControl1.GetTabRect(e.Index);
            tabRect.Inflate(-2, -2);
            if (e.Index == this.tabControl1.TabCount - 1)
            {
                // Add
                var addImage = Properties.Resources.Add;
                e.Graphics.FillRectangle(bshBack, e.Bounds);
                e.Graphics.DrawImage(addImage,
                    tabRect.Left   (tabRect.Width - addImage.Width) / 2,
                    tabRect.Top   (tabRect.Height - addImage.Height) / 2);
            }
            else
            {
                // Close
                var closeImage = Properties.Resources.Close;
                e.Graphics.FillRectangle(bshBack, e.Bounds);
                e.Graphics.DrawImage(closeImage,
                    (tabRect.Right - closeImage.Width),
                    tabRect.Top   (tabRect.Height - closeImage.Height) / 2);
                TextRenderer.DrawText(e.Graphics, tabPage.Text, tabPage.Font,
                    tabRect, tabPage.ForeColor, TextFormatFlags.Left);
            }
        }

CodePudding user response:

To extend the SOQ72179300

  • Related