在 Listview 中投射时出错:
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
int a = 1;
string theimage = textBox1.Text + @"\allimages\";
foreach (ListViewItem item in listView1.SelectedItems)
{
// 39 zero's + "1"
string initValue = new String('0', 3) + "0";
// convert to int and add 1
int newValue = Int32.Parse(initValue) + a;
// convert back to string with leading zero's
string newValueString = newValue.ToString().PadLeft(4, '0');
string imageslist = "product" + newValueString + "img";
string[] images = Directory.GetFiles(theimage, imageslist + "*.jpg");
// Cast the Picturebox
PictureBox myPicBox = new PictureBox();
myPicBox.Location = new Point(7, 240);
myPicBox.Size = new System.Drawing.Size(140, 140);
myPicBox.SizeMode = PictureBoxSizeMode.AutoSize;
myPicBox.Margin = new Padding(3,3,3,3);
myPicBox.Visible = true;
myPicBox.Image = new Bitmap(images[1]);
Controls.Add(myPicBox);
System.Diagnostics.Debugger.Break();
//List<PictureBox> pictureBoxList = new List<PictureBox>();
}
}
这是我的错误:
错误 1 'test.Form1.PictureBoxSizeMode()' 是一个'方法',在给定的上下文 C:\Users\radiaku\Documents\Visual Studio 2008\Projects\test\test\Form1.cs 428 37 测试中无效
当我使用 button_click 处理程序时,上面的代码工作正常。