Answer the question
In order to leave comments, you need to log in
Why calls the first form?
Hello everyone, I made a program with binding.
And for some reason, with a successful key, form1 remains, although I hid it.
I want form1 to disappear and form2 to appear. It appears anyway, but form1 does not disappear
string HWID;
private void label1_Click(object sender, EventArgs e)
{
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
WebClient Wanestian = new WebClient();
string Wanest1an = Wanestian.DownloadString("");
if (Wanest1an.Contains(HWID))
{
MessageBox.Show("Success!");
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
else
{
MessageBox.Show("Buy a license!");
Application.Exit();
}
}
Answer the question
In order to leave comments, you need to log in
Right now I can’t vouch for 100% fidelity, but at the start, the Show () method for the first form is executed.
What is there "under the hood" - I don't know, but you have code in Form_Load, which does not display the form itself. And since it is still shown at the start of the application, the change in the visibility of the form occurs after the Load has completed.
The order of events is:
HandleCreated
BindingContextChanged
Load
Control.VisibleChanged
Activated
Shown
Try moving the code to Shown. I think it will help in your case.
In general, according to the mind, it would be necessary to show Form2 from Main first, and only then Form1 according to the result.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question