Create a Form in constructor
-
Hi I want to create a Form in a constructor (or the load event) like this: public class Form1 { private Form fm; public Form1() { fm = new Form(); fm.Show(); } } It is important for me to use Show() and not ShowDialog(). The problem is, that the Form is created and displayed, but it does not react on any mouseclick (or move...). When I use the same code from within a Button callback everything works fine. As far as I could figure out by now, there is no Messageloop created in the CTOR or in the Load callback. So what options do I have? Thanks in advance remarks: The Form1 was created in an extra Thread. This seems to cause the problem. But I need this Thread. Snow. -- modified at 9:00 Tuesday 25th October, 2005
-
Hi I want to create a Form in a constructor (or the load event) like this: public class Form1 { private Form fm; public Form1() { fm = new Form(); fm.Show(); } } It is important for me to use Show() and not ShowDialog(). The problem is, that the Form is created and displayed, but it does not react on any mouseclick (or move...). When I use the same code from within a Button callback everything works fine. As far as I could figure out by now, there is no Messageloop created in the CTOR or in the Load callback. So what options do I have? Thanks in advance remarks: The Form1 was created in an extra Thread. This seems to cause the problem. But I need this Thread. Snow. -- modified at 9:00 Tuesday 25th October, 2005
Logically, the problem is that
Form1
hasn't been created yet nor is it isn't ready to be a "realized window" and yet you've created another window and tried to realize that. There is simply a mistiming of events in your logic (child window is created and displayed before the parent is created and displayed). I'm not surprised thatfm
never "appears". I would seperate theseForms
or at the very least move theShow
of the child form out of the contructor. You can still "parent" the one form off the other even if they are complete seperated objects. If you still want to agrigate the child form, show it on theLoad
event. That is my best guess without writing or compiling test code. -
Hi I want to create a Form in a constructor (or the load event) like this: public class Form1 { private Form fm; public Form1() { fm = new Form(); fm.Show(); } } It is important for me to use Show() and not ShowDialog(). The problem is, that the Form is created and displayed, but it does not react on any mouseclick (or move...). When I use the same code from within a Button callback everything works fine. As far as I could figure out by now, there is no Messageloop created in the CTOR or in the Load callback. So what options do I have? Thanks in advance remarks: The Form1 was created in an extra Thread. This seems to cause the problem. But I need this Thread. Snow. -- modified at 9:00 Tuesday 25th October, 2005
Your only option is to run a message pump on that thread also, using the Application.Run[^] method.
public Form1()
{
fm = new Form();
Application.Run(fm);
}Regards Senthil _____________________________ My Blog | My Articles | WinMacro