4

我需要在我的应用程序中更改 mdi 父级的背景颜色或背景图像。我尝试更改背景颜色或指定背景图像,但它不起作用。我还尝试循环表单中的控件以获取 mdiclient 并更改其背景色,结果也为零。

4

5 回答 5

1
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
于 2012-03-07T15:49:36.060 回答
1

也许这会有所帮助?http://support.microsoft.com/kb/319465

于 2010-03-30T13:21:31.817 回答
0

试试这个,它有效。

foreach (Control control in this.Controls)
{

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

}
于 2013-04-06T07:15:39.130 回答
0

如果您正在使用简单的颜色,请尝试以下代码,如果您正在尝试设置图像,则可以将 BackgroundImage 与 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.
                }
            }
于 2012-02-16T15:09:47.470 回答
0

尝试这个

  Public Sub MDIBGColor()
        Dim ctl As Control
        Dim ctlMDI As MdiClient

        ' Loop through all of the form's controls looking
        ' for the control of type MdiClient.
        For Each ctl In Me.Controls
            Try

                ' Attempt to cast the control to type MdiClient.
                ctlMDI = CType(ctl, MdiClient)

                ' Set the BackColor of the MdiClient control.
                ctlMDI.BackColor = Me.BackColor

            Catch exc As InvalidCastException
                ' Catch and ignore the error if casting failed.
            End Try
        Next

    End Sub

并在表单加载事件上调用 sub

于 2020-12-06T06:17:21.463 回答