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. Windows Forms
  4. Showing and manipulating a window form

Showing and manipulating a window form

Scheduled Pinned Locked Moved Windows Forms
question
7 Posts 4 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.
  • D Offline
    D Offline
    dj_jeff
    wrote on last edited by
    #1

    I want to open a window form by a method like that:

    frmForm frm_Form = new frmForm();
    frm_Form.Show();
    //here should be sth. manipulated
    frm_Form.Close();

    I've marked some window objects (text boxes) public, so I can call them outside.

    frm_Form.lblTest.Text = "Hello World";

    But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?

    J L D 3 Replies Last reply
    0
    • D dj_jeff

      I want to open a window form by a method like that:

      frmForm frm_Form = new frmForm();
      frm_Form.Show();
      //here should be sth. manipulated
      frm_Form.Close();

      I've marked some window objects (text boxes) public, so I can call them outside.

      frm_Form.lblTest.Text = "Hello World";

      But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?

      J Offline
      J Offline
      JoeSharp
      wrote on last edited by
      #2

      hi using(frmForm frm = new frmForm()) { frmForm.ShowWindow(this); // the using block call the Close/Dispose methode // so yopu don't need to call Close() or Dispose() } regards

      D 1 Reply Last reply
      0
      • D dj_jeff

        I want to open a window form by a method like that:

        frmForm frm_Form = new frmForm();
        frm_Form.Show();
        //here should be sth. manipulated
        frm_Form.Close();

        I've marked some window objects (text boxes) public, so I can call them outside.

        frm_Form.lblTest.Text = "Hello World";

        But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, if all the code you've shown is running on the GUI thread (say inside a button_click handler) then none of it will have a visible effect, since the GUI actions will get queued until your code reaches its end: it is only when the GUI thread is done dealing with the button click that it can start executing the queued stuff in a hurry. Do you really want to show a form and (almost immediately) close it again?? Normally a form gets closed by an explicit user action, such as clicking an OK button or the close box. Remedy: reorganise your code, at least separate the Form.Close from everything else (use another event, such as a button click, a timer tick, whatever). BTW: DO NOT include delays in handlers, don't try Thread.Sleep() inside a button click handler, it does not make any sense whatsoever. Mind you there is one dangerous hack that may or may not be useful here: include some Application.DoEvents() calls; they are bound to cause weird effects if used inappropriately though. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Fixturized forever. :confused:


        D 1 Reply Last reply
        0
        • J JoeSharp

          hi using(frmForm frm = new frmForm()) { frmForm.ShowWindow(this); // the using block call the Close/Dispose methode // so yopu don't need to call Close() or Dispose() } regards

          D Offline
          D Offline
          dj_jeff
          wrote on last edited by
          #4

          There is no ShowWindow method in C# in .NET Framework 2.0.

          1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, if all the code you've shown is running on the GUI thread (say inside a button_click handler) then none of it will have a visible effect, since the GUI actions will get queued until your code reaches its end: it is only when the GUI thread is done dealing with the button click that it can start executing the queued stuff in a hurry. Do you really want to show a form and (almost immediately) close it again?? Normally a form gets closed by an explicit user action, such as clicking an OK button or the close box. Remedy: reorganise your code, at least separate the Form.Close from everything else (use another event, such as a button click, a timer tick, whatever). BTW: DO NOT include delays in handlers, don't try Thread.Sleep() inside a button click handler, it does not make any sense whatsoever. Mind you there is one dangerous hack that may or may not be useful here: include some Application.DoEvents() calls; they are bound to cause weird effects if used inappropriately though. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Fixturized forever. :confused:


            D Offline
            D Offline
            dj_jeff
            wrote on last edited by
            #5

            There shouldn't be a button window close handling. This should be a status window running while actions (calling C# methods and functions) are running. That's why it should be opened when actions start and closed when finished.

            1 Reply Last reply
            0
            • D dj_jeff

              I want to open a window form by a method like that:

              frmForm frm_Form = new frmForm();
              frm_Form.Show();
              //here should be sth. manipulated
              frm_Form.Close();

              I've marked some window objects (text boxes) public, so I can call them outside.

              frm_Form.lblTest.Text = "Hello World";

              But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?

              D Offline
              D Offline
              dybs
              wrote on last edited by
              #6

              Try inserting

              frm_Form.Invalidate()

              when you want the form to update/refresh itself. (I wouldn't do this after every single content change, but probably after a group of updates). Invalidate() doesn't immediately update the form, but is usually sufficient. If Invalidate() doesn't update it when you expect, try calling

              frm_Form.Refresh()

              From my understanding, Refresh() prompts an immediate redraw of a form (although I could be mistaken). Brandon

              D 1 Reply Last reply
              0
              • D dybs

                Try inserting

                frm_Form.Invalidate()

                when you want the form to update/refresh itself. (I wouldn't do this after every single content change, but probably after a group of updates). Invalidate() doesn't immediately update the form, but is usually sufficient. If Invalidate() doesn't update it when you expect, try calling

                frm_Form.Refresh()

                From my understanding, Refresh() prompts an immediate redraw of a form (although I could be mistaken). Brandon

                D Offline
                D Offline
                dj_jeff
                wrote on last edited by
                #7

                Tried Refresh() and worked :), Invalidate didn't do it :(. Form won't only be displayed correctly in debugging mode. But that's ok. The best way of practise would be if I can do a periodical refresh on the form. But use of form object in Timer section and TimerElapsedEventHandler at the same time produces an error saying refresh can't be done when form is in both sections. If the user switches away and back to the program it seems as if the app has hung up. Because it's waiting for finishing the current process.

                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