2012-12-31 2 views
-2

얻기 오류 때 목록보기에서의 주조 :PictureBoxSizeMode가 오류입니까?

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>(); 
     } 

    } 

그것의 내 오류 :

Error 1 'test.Form1.PictureBoxSizeMode()' is a 'method', which is not valid in the given context C:\Users\radiaku\Documents\Visual Studio 2008\Projects\test\test\Form1.cs 428 37 test

내가 button_click 핸들러를 사용하는 경우 제대로 작동 위의 코드는 ..

+0

어떤 라인을 말하는 것입니까? 그리고'PictureBoxSizeMode'라는 메서드가 있습니까? –

+0

@JonSkeet 여기에'PictureBoxSizeMode.AutoSize;' – radiaku

답변

3

는 소리가 난다. 메서드 이름을 변경하거나 속성 설정자를 다음과 같이 변경할 수 있습니다.

myPicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; 

메서드 이름을 변경하면 더 명확 해집니다.

+1

일을 끝내려고했는데, 내 엉덩이를 다시 구해 줬어. : D – radiaku

0

그 오류가있는 경우에만 발생할 수 있습니다 코드에 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() 
{ 
} 

또는 다음과 같은 네임 스페이스로 한정하십시오. 양식이 PictureBoxSizeMode라는방법을 가지고 같은

myPicBox.SizeMode = myPicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; 
+0

... 전체 네임 스페이스 이름 (또는 별칭)으로'PictureBoxSizeMode' 열거 형을 한정하거나 한정합니다. 아마도 메서드를 제거하는 것이 더 쉽습니다. –

+0

@MattiVirkkunen, 고마워요. – Habib