【发布时间】:2017-01-03 01:37:43
【问题描述】:
Dictionary<int, PictureBox> aCollection;
aCollection = new Dictionary<int, PictureBox>();
aCollection.Add(333, new PictureBox
{
Name = "Alcoholism",
Image = Resources.alcoholism,
Size = new Size(22, 22),
SizeMode = PictureBoxSizeMode.StretchImage
});
aCollection.Add(289, new PictureBox
{
Name = "Hypertension",
Image = Resources.hypertension,
Size = new Size(22, 22),
SizeMode = PictureBoxSizeMode.StretchImage
});
PictureBox condition = aCollection[333]; //333 refers to alcoholism
condition.Location = new Point(450, 155);
displayForm.Controls.Add(condition);
PictureBox another = aCollection[289]; //289 refers to hypertension
another.Location = new Point(550, 155);
displayForm.Controls.Add(another);
上面的代码在 Winform 上呈现以下输出(注意图标):
但是,如果我将两个 PictureBox 切换为使用相同的图标,希望显示相同的图标两次,即
PictureBox condition = aCollection[289]; //Hypertension
condition.Location = new Point(450, 155);
displayForm.Controls.Add(condition);
PictureBox another = aCollection[289]; //Hypertension
another.Location = new Point(550, 155);
displayForm.Controls.Add(another);
我只得到一个图标输出。
有人可以告诉我哪里出错了吗?谢谢。
[编辑] - 下面的代码也只产生一个图标
PictureBox condition = aCollection[289];
condition.Location = new Point(450, 155);
displayForm.Controls.Add(condition);
PictureBox another = condition;
another.Location = new Point(550, 155);
displayForm.Controls.Add(another);
【问题讨论】:
-
PictureBox another = condition;怎么样,休息就这样吧。
标签: c# winforms picturebox