【问题标题】:Can't make PictureBox to be visible- C#无法使 PictureBox 可见-C#
【发布时间】:2013-01-12 19:49:03
【问题描述】:

我正在尝试使用 PictureBox 对象来显示图像,但我得到了一些“错误”。如果我只是添加 PictureBox 属性(位置、图像、大小、背景颜色等),我看不到任何图像

然后我读到我需要将 PictureBox 添加到表单控制器。

我添加了它,但仍然什么都没有......层有任何优先级(后面什么前面什么?,我该如何更改它?)

这是PictureBox的属性集:

imageFile = new PictureBox();
imageFile.Top = 200;
imageFile.Left = 400;
imageFile.Height = 100;// furnitureSize.Height;
imageFile.Width = 100;// furnitureSize.Width;
imageFile.ImageLocation = (Application.StartupPath + "\\ball4.gif");
imageFile.Image = Image.FromFile(Application.StartupPath + "\\lamp3.jpg");
imageFile.Visible = true;
imageFile.BackColor = Color.Black;
imageFile.SizeMode = PictureBoxSizeMode.StretchImage;
ownerForm.Controls.Add(imageFile);
imageFile.Show();

请帮忙。

【问题讨论】:

  • ownerForm.Controls.Add(imageFile);我猜这行有问题。
  • 是否有其他控件可以覆盖图片框?表格的大小是多少?

标签: c# image forms picturebox


【解决方案1】:

您必须为图片框定义大小

imageFile.ClientSize = new Size(100, 100);

【讨论】:

  • 我很乐意帮助你 SagiLow
【解决方案2】:

问题和我想的一样(pictureBox不在前面) 添加:imageFile.BringToFront(); 解决了这个问题

谢谢大家。

【讨论】:

  • 还是不明白为什么要同时使用ImageLocationImage 属性。
  • 尝试修复它...我删除了“ImageLocation”属性设置器
【解决方案3】:

嗯...你确定你的意思

ownerForm.Controls.Add(imageFile);

而不是

this.Controls.Add(imageFile);

?

【讨论】:

    猜你喜欢
    • 2020-01-09
    • 2011-04-02
    • 2012-07-15
    • 2015-11-03
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 2012-06-21
    相关资源
    最近更新 更多