✅ Winforms: open two forms at the same time

Good day everyone. So I have an issue (duhh, thats why I am here xD).

I am trying to get a screenshot of the users image...I am using two forms to achieve this, one to show the image and another to screenshot.
When I try open the first form AspectRatioForm and then the second SelectArea. It throws the issue below:
System.ArgumentException: 'Parameter is not valid.'


This is the code I wrote:
c#
public void openImageScreenshot(string imageLocationPath, PictureBox pictureBox)
{
    SelectArea area = new SelectArea(this);
   
    area.BringToFront();
    area.Activate();
    
    using (Image img = Image.FromFile(imageLocationPath))
    {
        AspectRatioForm aspectRatioForm = new AspectRatioForm(img);
        aspectRatioForm.Show();
    }
    this.Hide();
    area.ShowDialog();
    // After showing and hiding the SelectArea form, you can access the file path:
    string imagePathScreenshot = area.GetScreenshotFilePath();
    pictureBox.ImageLocation = imagePathScreenshot;
    this.Show();
}


Now I don't know why this is happening because if I call them separately in terms of their own functions using ShowDialog they both show one by one (once one form closes the other will show).
Was this page helpful?