由于某种原因,ArgumentException 提示“参数无效。”在执行以下任一操作时,Application.Run 会被抛出:
private void utilsTabBtn_Click(object sender, EventArgs e)
{
utilitiesPanel.BringToFront();
}
或者这个:
private void utilsTabBtn_Click(object sender, EventArgs e)
{
utilitiesPanel.Visible = true;
accountcreatorPanel.Visible = false;
aboutPanel.Visible = false;
}
在这段代码中执行RequestCaptcha后:
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);
}
}
所有控件(以“TabBtn”结尾的按钮和面板除外)都位于我试图隐藏的面板中。
最佳答案
在 RequestCaptcha() 方法中,您实际上正在处理图片框仍在使用的图像。
recaptchaBox.Image.Dispose();
以上行无效。或者你可以设置
pictureBox1.Image = null;
或者如果您确实打算处理该图像,您可以执行以下操作
Image image = recaptchaBox.Image;
recaptchaBox.Image = null;
image.Dispose();
这应该可以解决你的问题:)
关于c# - 将面板置于前面或更改可见性后,Application.Run 出现 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17557299/