2

我已经尝试了所有我能得到的东西,但它就是行不通!有没有人解决过这个问题?

我可以把我的图像放在后面,但它只有在表单从不尝试调整大小时才有效(缩小是可以的,生长会留下空白的灰色空间......)

4

10 回答 10

3

两种选择:

  • 设置背景图像并将 BackgroundImageLayout 属性更改为 Stretch (如 Guster_Q所建议)
  • 在图像控件中设置您的图像并将其停靠属性设置为填充
于 2009-08-22T18:16:41.840 回答
3

我尝试了 Form 的 resize 事件,它对我来说是这样的:

        private void Main_Resize(object sender, EventArgs e)
    {
        this.BackgroundImage = Properties.Resources.stockandinventorymanagement;
    }
于 2014-07-19T06:22:34.443 回答
1

将 RightToLeftLayout 属性设置为 FALSE

于 2014-09-16T04:25:31.447 回答
1

对于通过 Google 访问此页面的其他人,我在这里找到了解决此问题的方法。

通过将此代码放入表单的Initialize()函数中,我能够获得正常工作的 MDI 容器背景图像,即使是WindowState更改和调整表单大小:

// 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 容器使用表单BackgroundImage(无论如何它都隐藏了)和BackgroundImageLayout属性,以便我可以在 Designer 中使用表单自己的属性轻松设置/修改这些设置,并将这些设置自动反映在设计器无法访问的 MDI 容器中。这也意味着我不必担心管理图像的垃圾收集,并且可以摆脱Using {}在原始片段中找到的代码(这实际上会导致错误,因为图像本身由 Using 块处理,然后使表单崩溃一旦它试图显示现在丢失的图像)。

于 2020-09-19T19:33:02.870 回答
0

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

于 2009-08-22T16:26:06.557 回答
0

试试这个代码:

重要提示:表单的属性'BackgroundImageLayout'必须等于代码


        Dim ctl As Control

        For Each ctl In Me.Controls

            If TypeOf ctl Is MdiClient Then
                ctl.BackColor = Color.Yellow
                ctl.BackgroundImageLayout = ImageLayout.Stretch
                ctl.BackgroundImage = Image.FromFile("C:\Image.png")
            End If

        Next

于 2016-03-03T16:59:58.817 回答
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()
于 2018-01-10T14:38:35.173 回答
0
 private void MainMenu_Load(object sender, EventArgs e)
{
  foreach (Control ctrlControl in this.Controls)
  {
    if (ctrlControl is MdiClient)
    {
      BackgroundImage = Properties.Resources.Mbck;
    }
  }
}
于 2021-03-22T09:39:36.530 回答
0

我认为这个想法是将背景图像添加到对象的实例中,而不是对象的静态定义。

考虑到这一点,我所做的是:

  1. 将面板拖放到中间窗体上
  2. 让它停靠整个表格...不需要
  3. 将图片框添加到面板
  4. 在中间窗体的加载过程中,添加以下代码:
Me.picturebox1.image = image.fromfile("c:\filename.jpg")
Me.picturebox1.show()

它奏效了。

甚至可以通过不使用图片框和面板以及不是从磁盘而是从项目中的资源引用图像来使代码更流畅!

于 2021-08-27T16:54:06.423 回答
-3

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

于 2012-02-01T14:55:42.357 回答