2013-04-09 117 views
2

我一直在试图找出为什么当我的窗体运行,我使用下面的代码我的图像列表将不会呈现出我的图片...C#的ImageList也不会显示图像

public void renderImageList() 
    { 
     int selection = cboSelectedLeague.SelectedIndex; 
     League whichLeague = (League)frmMainMenu.allLeagues[selection]; 


     string index = cboSelectedLeague.SelectedItem.ToString(); 

     if (whichLeague.getLeagueName() == index) 
     { 
      foreach (Team t in allTeams) 
      { 
       Image teamIcon = Image.FromFile(@"../logos/" + t.getTeamLogo()); 

       imgLstIcons.Images.Add(teamIcon); 

      } 

     } 

     else 
     { 
      MessageBox.Show("Something went wrong..." + whichLeague.getLeagueName() + " " + index + "."); 
     } 

    } 

的方法是当用户更改我的组合框的索引时触发的,我知道该程序获得了正确的路径,因为我使用了一个消息框来显示每个路径按照我的预期返回的路径。

我是否错过了我的代码将图像绘制到框中?

Alex。

+1

你不应该使用PictureBox吗? ImageLists不用于直接在表单上显示图像,而是用作其他控件使用的一包资源。 http://stackoverflow.com/a/8587685/1373170 – 2013-04-09 16:49:33

+0

将图像绘制到哪个框?您可以从我所看到的内容中添加到“ImageList”中。这不显示图像... – MoonKnight 2013-04-09 16:49:35

+0

啊好吧,imageList被设置为我的listView顶部的largeImage控件 - 我需要将他们绘制到listView? – Alex 2013-04-09 16:51:26

回答

2

将所有图像到ImageList后,你应该所有项目添加到ListView还有:

for (int j = 0; j < imgLstIcons.Images.Count; j++) 
{ 
    ListViewItem item = new ListViewItem(); 
    item.ImageIndex = j; 
    lstView.Items.Add(item); 
} 

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/876b6517-7306-44b0-88df-caebf3b1c10f/

你也可以使用一个FlowLayoutPanel的和动态创建的PictureBox元素,每个图像一个,并且根本不使用ImageLists和ListViews。这取决于你想要的UI的类型。

+0

FlowLayoutPanel实际上听起来很有趣,我可以试试看,谢谢! – Alex 2013-04-10 20:57:31