2013-07-09 54 views
2

由於某種原因導致ArgumentException「參數無效」。執行時在Application.Run獲取引發任一此:在將面板置於前面或更改可見性後,Application.Run出現ArgumentException

private void utilsTabBtn_Click(object sender, EventArgs e) 
{ 
    utilitiesPanel.BringToFront(); 
} 

或該:

private void accountcreatorStartBtn_Click(object sender, EventArgs e) 
{ 
    accountcreatorStopBtn.Enabled = true; 
    accountcreatorStartBtn.Enabled = false; 
    recaptchaSolveBox.Enabled = true; 
    recaptchaContinueBtn.Enabled = true; 
    recaptchaRenewBtn.Enabled = true; 
    MinimalID = accIndexOne.Value; 
    CurrentID = MinimalID - 1; 
    MaximalID = accIndexTwo.Value; 
    RequestCaptcha(); 
    recaptchaBox.SizeMode = PictureBoxSizeMode.StretchImage; 
} 

其中RequestCaptcha是:

private void RequestCaptcha() 
{ 
    LatestKey = ((new Random()).Next() * (new Random()).Next()); 
    statusLbl.Text = "Captcha key: " + LatestKey.ToString(); 
    recaptchaBox.Image.Dispose(); 
    using (WebClient w = new WebClient()) 
    { 
     w.DownloadFile(string.Format(RequestURL, LatestKey), Environment.CurrentDirectory + "/latestCaptcha.jpg"); 
    } 
    try 
    { 
     recaptchaBox.Image = Image.FromFile(Environment.CurrentDirectory + "/latestCaptcha.jpg"); 
    } 
    catch (Exception ex) 
    { 
     recaptchaBox.Image = recaptchaBox.ErrorImage; 
     MessageBox.Show(ex.Message, this.Text + " - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
    } 
} 

private void utilsTabBtn_Click(object sender, EventArgs e) 
{ 
    utilitiesPanel.Visible = true; 
    accountcreatorPanel.Visible = false; 
    aboutPanel.Visible = false; 
} 

在這種代碼執行RequestCaptcha後

所有控件,除了以'TabBtn'結尾的按鈕和麪板外,都在我試圖隱藏的面板中。

+0

你試過把一個斷點處最初的事件,然後進入它? – Logarr

+0

我遍歷整個程序,只要utilsTabBtn_Click完成,就會拋出異常。 – 0x47686F7374

+0

我不能從提供的示例中知道,但也許這個答案會有一些用處:[回覆](http://stackoverflow.com/a/389561/1127924) – Logarr

回答

2

在RequestCaptcha()方法中,你實際上正在處理仍在被圖片框使用的圖像。

recaptchaBox.Image.Dispose(); 

上方無效。另外,您可以設置

pictureBox1.Image = null; 

,或者如果你真的打算處置圖像,你可以做以下

Image image = recaptchaBox.Image; 
recaptchaBox.Image = null; 
image.Dispose(); 

應該解決您的問題:)

+0

這樣做!謝謝! – 0x47686F7374

+0

不客氣 –