Hi all,
Is there any way of knowing when the Application.Run(MainForm) has finished showing the MainForm
I need to show another form on top of the MainForm, but i don't know when it's loading is finished and the new form is always hidden by the MainForm...
Any help would be great!
Regards,
Pedro

Knowing when Application.Run(MainForm) has finished showing the MainForm
Malazar
Unfortunately I have yet another problem... the OnPaint method isn't called in my main form, which only has a ListView with Dock set to fill :(
If the ListView isn't with Dock set to fill, then it is called, otherwise it isn't...
This is getting a little frustrating...
Raptorix
So the MainForm is yours and Form2 is the one you don't have access to Why can't you run the method which pops up the Form2 in Activated event of the MainForm
David pereira
The problem is that I don't have control over the second form, I can only start it because it's in a 3rd party dll.
I've tried starting it in the activated event, and even in the GotFocus, but it always gets behind the first one!!!
I really need to know when the 1st form finishes showing, but I don't have a clue how!!
AHTUNG
I've already tried doing that, but it doesn't work. I think that the internal procedure of the Show() (or Visible=true) method triggers the onActivated and after, it verifies if the form is being shown. If it isn't, it shows it again.
1:MainForm is visible ([Top] MainForm)
2: the Activated event is raised ([Top] MainForm)
3:I show the 2nd Form ([Top] 2ndForm, MainForm)
4:Internally the MainForm is set visible again ([Top] MainForm, 2ndForm)
But I think I found a way, overriding the onPaint. It seems that the onPaint is the last to be called, and I can do this:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (!_loadComplete)
{
_loadComplete = true;
Form1 c = new Form1();
c.Show();
}
}
Thomas Ivarsson
You can show second form from Activated event of the first form, make sure first form is a parent of a second one.
I know some developers are trying to do something like this:
Application.Run(MainForm)
Application.Run(SomeForm)
That would never work – generally you can only have one Application.Run() per application.
su45937
Usual patter for forms would involve some user interaction, e.g. user pushes the button on MainForm and Form2 pops up. However your case is not like that, your MainForm does nothing but popping up Form2. I suppose you can simulate normal pattern with, say, timer like this:
private bool isFirstActivation = true;
private void Form1_Activated(object sender, EventArgs e)
{
if (isFirstActivation)
{
Timer timer = sender as Timer;
if (null == timer)
{
timer = new Timer();
timer.Tick += Form1_Activated;
timer.Interval = 10;
timer.Enabled = true;
}
else if (this.Visible)
{
isFirstActivation = false;
timer.Enabled = false;
timer.Tick -= Form1_Activated;
timer.Dispose();
Form2.ShowForm();
}
}
}
perezd
Sure you do. If you can "start" it, you have reference to the instance so you can subscribe to Activated event and you can set it as parent for your new form. You do not need source code to do all that.
nmacro
Actually I can't. I don’t have control over the second form, I simply run a method which internally shows the form, not giving me access to its instance.
The best I can do is run the method in the GotFocus of the MainForm, wich is activated when Application.Run(MainForm) internally sets the form visibility to true. The problem is that while its processing Visible=true, it verifies that the MainForm isnt anymore visible, and Shows it again, triggering again the GotFocus!
Therefore, the visible form stack is:
Form2
Mainform
Form2 (Top)
or if I only alow the gotFocus code to run once:
Form2
MainForm (Top)
When what I really want is :
MainForm
Form2 (Top)
Did you understand my problem
Thanks for the help!