MetroFramework for windows forms project and tab control rendering issue

1k views Asked by At

I'm not sure where to begin here in order to troubleshoot and work on the 3rd party code to try and fix this so I thought I would ask here and show a screen of the issue. I am using a third party windows form "metro controls" package from https://thielj.github.io/MetroFramework/ and it looks a bit dated and no longer maintained and the only real issue I am having is that the tab control specifically seems to have extra rendering "junk" that goes away when you click it. But I don't know why it's drawn in the first place or how to go about removing / fixing it and updating the package on github. The UI package is useful it makes a plain windows form project look much nicer and have a far better UI so that's the reason I picked it up.

Is anyone familiar with this library and having similar issues or know the best way to approach fixing it myself? Keep in mind I am not familiar with the drawing/gui portion of windows forms at all and usually reference online material when it comes to drawing or UI type work.

enter image description here

2

There are 2 answers

0
fr332lanc3 On

Turned out I found this library instead (slightly newer / more updates) https://www.nuget.org/packages/MetroModernUI/ but still has some similar issues I am having however I modified the code slightly to help accommodate one of the issues I am having, the OnDrawItem event lifecycle seems to be gone for setting OwnerDrawFixed property on a tab control.

Here is the code I modified in MetroTabControl.cs and I am just using a local version/build to support any customizations and enhancements I have to do since there is a few other problems I have as well.

        private void DrawTab(int index, Graphics graphics)
        {
            Color foreColor;
            Color backColor = BackColor;

            if (!useCustomBackColor)
            {
                backColor = MetroPaint.BackColor.Form(Theme);
            }

            TabPage tabPage = TabPages[index];
            Rectangle tabRect = GetTabRect(index);

            if (!Enabled || tabDisable.Contains(tabPage.Name))
            {
                foreColor = MetroPaint.ForeColor.Label.Disabled(Theme);
            }
            else
            {
                if (useCustomForeColor)
                {
                    foreColor = DefaultForeColor;
                }
                else
                {
                    foreColor = !useStyleColors ? MetroPaint.ForeColor.TabControl.Normal(Theme) : MetroPaint.GetStyleColor(Style);
                }
            }

            if (index == 0)
            {
                tabRect.X = DisplayRectangle.X;
            }

            Rectangle bgRect = tabRect;

            tabRect.Width += 20;

            using (Brush bgBrush = new SolidBrush(backColor))
            {
                graphics.FillRectangle(bgBrush, bgRect);
            }

            TextRenderer.DrawText(graphics, tabPage.Text, MetroFonts.TabControl(metroLabelSize, metroLabelWeight),
                                  tabRect, foreColor, backColor, MetroPaint.GetTextFormatFlags(TextAlign));

            //HACK not properly handling the owner draw fixed event/override life cycle so we can fire it ourselves and if something is listening
            //      it will execute
            if (this.DrawMode == TabDrawMode.OwnerDrawFixed)
            {
                OnDrawItem(new DrawItemEventArgs(graphics, this.Font, tabRect, index, DrawItemState.None));
            }
        }

For the other UI issue I am tracking down where I can invalidate or fix the odd additional button / clickable disappearing areas in the tab control or panels for this UI enhancement framework.

0
Đỗ Tiến Hưng On

What happens is that there should be some error related to the Size of the MetroTabControl, and you can fix that with the following code:

        this.metroTabPage1.VerticalScrollbarBarColor = false;
        this.metroTabPage1.VerticalScrollbarSize = 0;