面板中PictureBox的图像 [英] Image of PictureBox in a Panel

查看:86
本文介绍了面板中PictureBox的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个图片框控件数组,因此我使用了一个面板来容纳它们.但是,之后我发现该图像已被禁用.我必须改为使用BackgroundImage吗? :(

I wanna create an array of picturebox controls, so I used a panel to hold them. However, afterwards I found that the Image has been disabled. Do I have to use BackgroundImage instead? :(

推荐答案

我认为从阅读这两行之间可以看到:

1)制作一个面板
2)动态创建一个PictureBox控件数组,每个控件用于显示图像.
3)试图设置Image属性,并被告知它不存在,因此正尝试使用BackgroundImage属性.

这意味着您尝试的是
I think from reading between the lines that you have:

1) Constructed a panel
2) Dynamically created an array of PictureBox controls, each to display an image.
3) Tried to set the Image property, and been told it doesn''t exist, so are trying to use the BackgroundImage property instead.

This implies that what you tried was
Panel1.Image = new Image(@"c:\...

,但是编译器抱怨.
Panel控件不具有Image属性(irt具有BackgroundImage,但这不是您想要的).您需要做的是改为设置每个PictureBox控件的Image属性.

您是否已将PictureBox控件添加到Panel.Controls列表中?
您是否给他们提供了所有新的位置"属性和适当的大小?
如果您有很多图像,最好使用Paint事件自己绘制它们.

but the compiler complained.
A Panel control does not have an Image property (irt does have a BackgroundImage, but this is not what you want). What you need to do is set the Image property of each PictureBox control instead.

Have you added the PictureBox controls to the Panel.Controls list?
Have you given them all new Location properties, and appropriate sizes?
If you have many images, you may be better off drawing them yourself with the Paint event.


下面的代码,创建一个10索引的PictureBox数组,并分配其大小,位置,名称,然后将其连续放置在面板上.也许您可以以某种方式使用它:

the code below, creates an 10 index array of PictureBox, and assign their Sizes, Locations, Names, Images and put them on a panel in a row. may be you can use it somehow :

<br />
           PictureBox[] Pix = new PictureBox[10];<br />
           for (int i = 0; i < 10; i++)<br />
           {<br />
               Pix[i] = new PictureBox();<br />
               Pix[i].Image = Image.FromFile(@"C:\bmp.bmp");<br />
               Pix[i].SizeMode = PictureBoxSizeMode.StretchImage;<br />
               Pix[i].Name = string.Format("Image{0}", i);<br />
               Pix[i].Size = new Size(10, 10);<br />
               Pix[i].Location = new Point(i * 10, 0);<br />
               panel1.Controls.Add(Pix[i]);<br />
           }<br />



----------------------
问候

H.Maadani



----------------------
Regards

H.Maadani


这篇关于面板中PictureBox的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆