控制PictureBox问题

时间:2011-02-20 11:30:21

标签: c# winforms

我有这个Enum

public  enum Icon
{
    Question    = 1,
    Hand        = 2,
    Exclamation = 3,
    None        = 4
}

我的表单上有4个PictureBox,名为

P1 , P2 , P3 and P4

如果我有Icon G

我怎么能像这样展示任何PictureBox:

而不是P2.visible = true我会写G.Hand = True

提前致谢

1 个答案:

答案 0 :(得分:2)

我认为不需要四个PictureBox控件,您只需要一个并在枚举上选择一个图像库,如下所示:

// Assuming you have a dictionary of icons pathes
Dictionary<Icon,string> icons = new Dictionary<Icon,string>();

icons[Icon.Question] = "..\imgQuestion.png" \\ path of question image";
icons[Icon.Hand] =
icons[Icon.Exclamation] =

pictureBoxControl.Image = icons[G.Hand];
祝你好运!