MDI父母背景图像

时间:2009-08-22 16:10:48

标签: c# image background parent mdi

我已经尽力尝试了所有可以接触到的东西,但它无法正常工作! 有没有人解决过这个问题?

我可以将我的图像放在后面,但只有在表单从未尝试调整大小时才会起作用(缩小是正常的,不断增长会留下空白的灰色空间......)

9 个答案:

答案 0 :(得分:3)

两个选项:

  • 设置背景图像并更改 BackgroundImageLayout属性为 拉伸(如建议的那样) Guster_Q
  • 在图像控件中设置图像 设置对接属性以填充

答案 1 :(得分:3)

我尝试过Form&#39的resize事件,它对我有用:

        private void Main_Resize(object sender, EventArgs e)
    {
        this.BackgroundImage = Properties.Resources.stockandinventorymanagement;
    }

答案 2 :(得分:0)

将BackgroundImageLayout属性更改为Stretch。这将拉伸您的图像以始终填充背景空间。

答案 3 :(得分:0)

很久以前,我发现使用面板作为MDI容器可以轻松解决这个问题。

答案 4 :(得分:0)

将RightToLeftLayout属性设置为FALSE

答案 5 :(得分:0)

试试这段代码:

重要提示:属性' BackgroundImageLayout'形式必须等于代码

SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(128, 0, 0, 255));
graphics.FillPath(semiTransBrush, graphicsPath);

答案 6 :(得分:0)

谢谢你的想法!!!! 只是更改面板的背景并将其放在下面的代码中,这太简单了 C#:

Form2 frm = new Form2();
        frm.TopLevel = false;
        panel1.Controls.Add(frm);
        frm.Show();

这适用于vb.net

    Dim frm  = New Form2
    frm .TopLevel = False
    Panel1.Controls.Add(frm )
    frm .Show()

答案 7 :(得分:0)

对于通过Google到达此页面的其他人,我找到了解决此问题的方法here

通过将此代码放入表单的Initialize()函数中,即使进行WindowState更改和调整表单大小,我也可以得到正确的MDI容器背景图片:< / p>

// as this code occurs in the Form's "Initialize()" function, any references to
// "this." are to the Form instance itself (not the MDI control!)
MdiClient client = this.Controls.OfType<MdiClient>().First();
client.BackgroundImageLayout = this.BackgroundImageLayout;
client.Paint += ( s, e ) => 
    e.Graphics.DrawImage( this.BackgroundImage, (s as MdiClient).ClientRectangle );

//Set this to repaint when the size is changed
typeof( Control ).GetProperty( 
    "ResizeRedraw", 
    System.Reflection.BindingFlags.NonPublic | 
    System.Reflection.BindingFlags.Instance 
).SetValue( client, true, null );

//set this to prevent flicker
typeof( Control ).GetProperty( 
    "DoubleBuffered", 
    System.Reflection.BindingFlags.NonPublic | 
    System.Reflection.BindingFlags.Instance 
).SetValue( client, true, null );

为简单起见,我使MDI容器使用了Form的BackgroundImage(无论如何都会隐藏)和BackgroundImageLayout属性,以便我可以使用Designer和Designer中Form自己的属性轻松地设置/修改这些设置。将那些设置自动反映在设计者不可访问的MDI容器中。这也意味着我不必担心管理图像的垃圾收集,并且可以摆脱原始代码段中的Using {}代码(由于图像本身是由Using块处理的,因此实际上会导致错误)然后在试图显示现在丢失的图像后立即将其崩溃)。

答案 8 :(得分:0)

 private void MainMenu_Load(object sender, EventArgs e)
{
  foreach (Control ctrlControl in this.Controls)
  {
    if (ctrlControl is MdiClient)
    {
      BackgroundImage = Properties.Resources.Mbck;
    }
  }
}
相关问题