A
A
Alexander2017-05-06 20:11:05
C++ / C#
Alexander, 2017-05-06 20:11:05

Why is the form not hidden?

If I register in an event, then nothing happens.

private void Form1_Load(object sender, EventArgs e)
{
    Form1 f = new Form1();
    f.Hide();
}

And if I write in public Form1 (), then it creates a StackOverflowException:
public Form1()
{
    Form1 f = new Form1();
    f.Hide();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2017-05-06
@AlexNineteen

in the first case - you create a new object of type Form1 and hide it. From here, the effect is zero. Those. you created another object and hide it. Not the main form...
in the second case - there is a recursion - i.e. an object (of type Form1) creates itself in the image and likeness of the "original", then the second object creates itself in the image of the "original", etc., until the memory buffer overflows.
To hide the form (the current one in which you are working) it is enough
this.Hide();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question