Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Create a Form in constructor

Create a Form in constructor

Scheduled Pinned Locked Moved C#
javascripthelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pixinger77
    wrote on last edited by
    #1

    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

    T S 2 Replies Last reply
    0
    • P Pixinger77

      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

      T Offline
      T Offline
      Tom Larsen
      wrote on last edited by
      #2

      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 that fm never "appears". I would seperate these Forms or at the very least move the Show 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 the Load event. That is my best guess without writing or compiling test code.

      1 Reply Last reply
      0
      • P Pixinger77

        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

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups