문제

For some reason an ArgumentException saying 'Parameter is not valid.' at Application.Run gets thrown when executing either this:

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

or this:

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

after executing RequestCaptcha in this code:

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

where RequestCaptcha is:

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

ALL controls, with exception to the buttons ending with 'TabBtn' and the panels, are in the panel I'm trying to hide.

도움이 되었습니까?

해결책

Inside RequestCaptcha() method you are actually disposing the image which is still being used by picture box.

recaptchaBox.Image.Dispose();

above line is not valid. alternatively you could set

pictureBox1.Image = null;

or if you intend really to dispose the image you can do the following

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

that should solve your problem :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top