C#的ImageList也不会显示图像 [英] C# ImageList won't display images
问题描述
我一直在试图找出为什么当我的窗体运行,我使用下面的代码我的图像列表将不会呈现出我的图片...
I've been trying to figure out why my imageList won't render out my images when my form runs, I am using the following code...
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 + ".");
}
}
该方法被触发,当用户改变了我的组合框的指标,我知道程序获取为我所用消息框来显示,因为我预料到的每个路径返回的路径的正确路径。
The method is fired when the user changes the index of my combo box, I know the program gets the correct path as I used a message box to display the path each path returned as I expected it to.
我失去了从我的代码的东西图像绘制到箱子里吗?
Am I missing something from my code to draw the image to the box?
亚历克斯。
推荐答案
将所有图像到ImageList后,你应该将所有项目添加到ListView还有:
After adding all images to the ImageList, you should add all the items to the ListView as well:
for (int j = 0; j < imgLstIcons.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
lstView.Items.Add(item);
}
您也可以使用FlowLayoutPanel的和动态创建的PictureBox元素,为每个图像,而不是在所有使用图像列表和列表视图。这取决于你想要的UI类型。
You can also use a FlowLayoutPanel and dynamically create PictureBox elements, one for each Image, and not use ImageLists and ListViews at all. It depends on the type of UI you want.
这篇关于C#的ImageList也不会显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!