如何在listvIEw中插入圖片,相信大家很想知道,下面就為大家分享具體步驟:
第一步:在窗體中拖入ListVIEw控件和imageList控件;
第二步:設置imageList控件的Images屬性,添加你想要的圖片;
第三步:設置ListVIEw控件的SmallImageList、LargeImageList、StateImageList屬性為imageList;
第四步:編輯ListVIEw控件項的ImageIndex行為你就會發現圖片成功顯示出來了!
附:在ListVIEw控件中添加選項的代碼
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("添加的內容不能為空");
textBox1.Focus(); //獲取焦點
}
else
{
if (listVIEw1.Items.Count > 0) //判斷列表框中是否有項
{
//循環比較是否有重復項,有則放棄添加
for (int i = 0; i < listVIEw1.Items.Count; i++)
{
if (string.Compare(listVIEw1.Items[i].Text.ToString(), textBox1.Text) == 0)
{
MessageBox.Show("項目重復,不能添加!");
textBox1.Text = ""; //清空文本框
textBox1.Focus();
return;
}
}
listVIEw1.Items.Add(textBox1.Text.ToString());
textBox1.Text = "";
}
else
{
listVIEw1.Items.Add(textBox1.Text.ToString()); //將文本框中的數據添加到列表框
textBox1.Text = "";
}
}
}
以上就是本文的全部內容,希望本文所述對大家學習C#程序設計有所幫助。