PictureBoxSizeMode is error?
本文关键字:error is PictureBoxSizeMode | 更新日期: 2023-09-27 17:50:01
在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>();
}
}
是我的错:
当我使用button_click处理程序时,上面的代码工作得很好。错误1 'test. form1 . pictureboxsizemode()'是一个'方法',在给定的上下文中无效C:'Users'radiaku'Documents'Visual Studio 2008'Projects'test'test'Form1.cs 428 37 test
听起来你的表单有一个方法叫做PictureBoxSizeMode
。您可以更改方法名称,或者将属性设置器更改为:
myPicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
只有在代码中有一个名为PictureBoxSizeMode
的方法时才会发生该错误。您应该将该方法重命名为其他东西。像这样的场景:
private void UserInput_KeyPress(object sender, KeyPressEventArgs e)
{
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;
}
private void PictureBoxSizeMode()
{
}
或者用命名空间来限定它。
myPicBox.SizeMode = myPicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;