リストビューでのキャスト時にエラーが発生しました:
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 test
上記のコードは、button_click ハンドラーを使用すると正常に動作します。