Cannot hide MetroForm in C#

40 views Asked by At

So here is my code: https://ptero.co/hasunotuwi.cs

I'm making a license system, I want to hide the MetroForm after the key is invalid or if the key isn't found in the database. It's a school project, so don't worry about the DB credentials being in plain-text. After I run the code It should display a MessageBox saying "Your activation is not valid." and hide the MetroForm. Instead it displays the MessageBox and the MetroForm shows up like nothing happened.

1

There are 1 answers

0
FroZen Mitko On BEST ANSWER

The problem was fixed. The thing is that Load event is executed before the form shows, so there is nothing to hide. Instead I created a bool named isHidden and assigned false to it. Next, I assigned true whenever I needed the form to hide and last I created a void for the Shown event and it looked like this:

private void Form1_Shown(object sender, EventArgs e)
{
    if(isHidden)
    {
        Hide();
    }
}