Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 如何在MDIParent';s控件_Winforms_Visual Studio 2008_C# 3.0_Mdichild_Mdiparent - Fatal编程技术网

Winforms 如何在MDIParent';s控件

Winforms 如何在MDIParent';s控件,winforms,visual-studio-2008,c#-3.0,mdichild,mdiparent,Winforms,Visual Studio 2008,C# 3.0,Mdichild,Mdiparent,我有一个包含许多子窗体的MDI父窗体,当我想在父窗体上添加控件时,子窗体会显示在该控件下,例如,我想在MDI父窗体上添加一个groupbox和一个PictureBox,但当我调用子窗体时,它会显示在这些控件下 frmChildForm1.TopMost=true也不起作用 我附上了一张照片,以作更多描述 我能做什么 但是我想要一个图像作为背景 这是可能的,您可以设置MDI客户端控件的BackgroundImage属性。唯一的障碍是您无法直接获取该控件的引用。您必须通过迭代表单的控件集合来找到它

我有一个包含许多子窗体的MDI父窗体,当我想在父窗体上添加控件时,子窗体会显示在该控件下,例如,我想在MDI父窗体上添加一个groupbox和一个PictureBox,但当我调用子窗体时,它会显示在这些控件下

frmChildForm1.TopMost=true
也不起作用

我附上了一张照片,以作更多描述

我能做什么

但是我想要一个图像作为背景

这是可能的,您可以设置MDI客户端控件的BackgroundImage属性。唯一的障碍是您无法直接获取该控件的引用。您必须通过迭代表单的控件集合来找到它。像这样:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        foreach (Control ctl in this.Controls) {
            if (ctl is MdiClient) {
                ctl.BackgroundImage = Properties.Resources.Lighthouse;
                break;
            }
        }
    }
}

其中Lighthouse是我作为资源添加的示例图像。将其更改为使用您自己的。另一种常见的技术是订阅该控件的Paint事件并绘制所需的任何内容。渐变是一种常见的选择。

这是设计的。您只能设置控件的Dock属性来避免这种情况。将其停靠在边缘上,以便缩小MDI客户端区域。是的,但我希望有一个图像作为背景,它不显示,我必须使用图片框,因此我还有类似的问题谢谢!这就是我的解决方案:)它对我很有效,但是,我的背景是从
右侧
底部
边界重复的,为什么会这样?我还将其布局更改为
stretch
,但仍然是相同的prob
foreach(this.Controls中的Control ctl){if(ctl是MdiClient){ctl.BackgroundImage=Properties.Resources.bg;ctl.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Stretch;break;}
像这样,我使用了BackgroundImageLayout属性。您必须单击“提问”按钮。我已在此处发布了问题