Change backcolor or background image of a MDI Container form in .net

倖福魔咒の 提交于 2019-12-10 21:49:39

问题


i need to change the backcolor or background image of a mdi parent in my application. i tried changing the backcolor or specifying a background image, it won't work. i also tried looping the controls in the form to get the mdiclient and change its backcolor, also zero same result.


回答1:


Maybe this will help? http://support.microsoft.com/kb/319465




回答2:


Private ClientControl As MdiClient

    Public Sub New()
        InitializeComponent()

        ClientControl = Nothing
        For Each Ctl As Control In Me.Controls
            ClientControl = TryCast(Ctl, MdiClient)
            If ClientControl IsNot Nothing Then Exit For
        Next
    End Sub

'iN FORM LOAD

ClientControl.BackColor = Color.Cyan



回答3:


If you are doing a simple colour then try the below code, if you are trying to set an image then you can use BackgroundImage with BackgroundImageLayout

 MdiClient ctlMDI;
            foreach (Control ctl in this.Controls)
            {
                try
                {
                    ctlMDI = (MdiClient)ctl;

                    // Set the BackColor of the MdiClient control.
                    ctlMDI.BackColor = Color.DarkRed;
                }
                catch (InvalidCastException exc)
                {
                    // Catch and ignore the error if casting failed.
                }
            }



回答4:


Try this, it works.

foreach (Control control in this.Controls)
{

    // #2
    MdiClient client = control as MdiClient;
    if (!(client == null))
    {
        // #3
        client.BackColor = GetYourColour();
        // 4#
        break;
    }

}


来源:https://stackoverflow.com/questions/2542972/change-backcolor-or-background-image-of-a-mdi-container-form-in-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!