C# Winform show unwanted Background color in the child form

0

Issue

I don’t know why my app shows a white background. I didn’t set any white background in any form whether it is parent or child. I have tried everything and set every panel back color to transparent but the white color is still there.

Please see the below image where I mark white color in blue marker.

WinForm Screenshot

I am using .Net Framework 4.7 and using Guna2 Framework for UI components.

I am using Dock property for responsiveness

I have created different forms for the each Menu Panel, Whenever the Menu panel click then it’s form will be displayed in the area where I am facing the issue related to white color.

I have a parent/startup form where I have multiple panels for Menu, Head Title, and the one main panel which named as Child Panel.

Child Panel is the Panel where I Add the respective form into the panel controls & show it.

I always put the BoarderStyle property as None in all forms.

I have tried to put margin & padding 0 in everywhere but it still shows the white color.

This is my home/parent form

This is my child Form which I add in child panel of parent Form

This is the method to show the child form into the Child Panel Of the Parent Form

#region Show Child Form
        public static void ShowChildForm(object FormObject, Panel childPanel, string ArchiveBasePath = null)
        {
            try
            {
                var newForm = FormObject as Form;
                if (ArchiveBasePath != null)
                {
                    var isDark = FileEncrypt.GetArchiveData<bool>(ArchiveBasePath + @"\" + ColorTheme.Archive_ThemeSetting);
                    if (isDark)
                        ColorTheme.ChangeTheme(new ColorScheme(true), newForm.Controls);
                    else // Dark Mode Disabled
                        ColorTheme.ChangeTheme(new ColorScheme(false), newForm.Controls);
                }

                if (!childPanel.Contains(newForm))
                {
                    newForm.TopLevel = false;
                    newForm.Dock = DockStyle.Fill;
                    newForm.Padding = new Padding(0,0,0,0);
                    if (childPanel.Controls.Count > 0)
                        childPanel.Controls.RemoveAt(0);
                    childPanel.Controls.Add(newForm);
                    childPanel.Tag = newForm;
                    newForm.Show();
                }
            }
            catch (Exception) { }
        }
        #endregion

This the the ColorTheme class to enable/disable Dark Mode

 public class ColorTheme
    {
        public static string Archive_ThemeSetting = "ThemeSetting.dat";

        public static string ColorChangeTag = "ColorChange";
        public static string ColorChangeLight = "ColorChangeLight";
        public static string ColorLabel = "ColorLabel";

        public static void ChangeTheme(ColorScheme color, Control.ControlCollection container)
        {
            foreach (Control component in container)
            {
                if (component is Guna2ShadowPanel)
                {
                    ChangeTheme(color, component.Controls);
                    if (component.Tag == ColorChangeTag)
                    {
                        //((Guna2ShadowPanel)component).BackColor = ColorTranslator.FromHtml(color.MainPanelColor);
                        ((Guna2ShadowPanel)component).FillColor = ColorTranslator.FromHtml(color.MainPanelColor);
                        //component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
                    }
                    else if (component.Tag == ColorChangeLight)
                    {
                        //((Guna2ShadowPanel)component).BackColor = ColorTranslator.FromHtml(color.ChildPanelColor);
                        ((Guna2ShadowPanel)component).FillColor = ColorTranslator.FromHtml(color.ChildPanelColor);
                    }
                    component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
                }
                else if (component is Guna2Panel)
                {
                    ChangeTheme(color, component.Controls);
                    if (component.Tag == ColorChangeTag)
                    {
                        //((Guna2Panel)component).BackColor = ColorTranslator.FromHtml(color.MainPanelColor);
                        ((Guna2Panel)component).FillColor = ColorTranslator.FromHtml(color.MainPanelColor);

                    }
                    else if (component.Tag == ColorChangeLight)
                    {
                        //((Guna2Panel)component).BackColor = ColorTranslator.FromHtml(color.ChildPanelColor);
                        ((Guna2Panel)component).FillColor = ColorTranslator.FromHtml(color.ChildPanelColor);
                    }
                    component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
                }
                else if (component is Panel)
                {
                    ChangeTheme(color, component.Controls);
                    if (component.Tag == ColorChangeTag)
                        component.BackColor = ColorTranslator.FromHtml(color.MainPanelColor);
                    else if (component.Tag == ColorChangeLight)
                        component.BackColor = ColorTranslator.FromHtml(color.ChildPanelColor);
                    component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
                }
                else if (component is Guna2Button)
                {
                    if (component.Tag == ColorChangeTag)
                    {
                        //((Guna2Button)component).FillColor = ColorTranslator.FromHtml(color.MainPanelColor);
                        component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
                    }
                    else if (component.Tag == ColorChangeTag)
                    {

                    }
                }
                else if (component is TextBox)
                {
                    if (component.Tag == ColorChangeTag)
                    {
                        component.BackColor = ColorTranslator.FromHtml(color.MainPanelColor);
                        component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
                    }
                }
                else if (component is Label)
                {
                    if (component.Tag == ColorLabel)
                    {
                        component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
                    }
                }
                else if (component is MenuPanelButton)
                    ChangeTheme(color, component.Controls);

                //System.Console.WriteLine(component.Name + ": " + color.ChildPanelColor);
            }
        }

        public static void ChangeColor(ColorScheme color, Control component)
        {
            component.BackColor = ColorTranslator.FromHtml(color.MainPanelColor);
            component.ForeColor = ColorTranslator.FromHtml(color.MainPanelForeColor);
        }
    }

Solution

I am facing the issue in parent form where I have some white border but I have never used any borderstyle

enter image description here

Problem solve by removing the shadow from the parent form which is generated at runtime

Answered By – Fazeel Ahmed

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More