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. ReLoad Form Problem

ReLoad Form Problem

Scheduled Pinned Locked Moved C#
game-devhelptutorial
12 Posts 5 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.
  • M Offline
    M Offline
    monafr81
    wrote on last edited by
    #1

    I am working on a small game , and i have a problem -- when the user win a message box appear asking him if he want to play again if he answered -yes- the form must be shown again as it was in the beginning of the game , and i do not know how to reload the form :confused: thanks , Mona

    LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

    N L 2 Replies Last reply
    0
    • M monafr81

      I am working on a small game , and i have a problem -- when the user win a message box appear asking him if he want to play again if he answered -yes- the form must be shown again as it was in the beginning of the game , and i do not know how to reload the form :confused: thanks , Mona

      LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

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

      Hi, AFAIK you can load a form only once. But you can show and hide it many times using either Show()/Hide() methods or setting Visible property true/false. Apart from that, you could create a new instance of your form, which would give you its initial state automatically (wanted or not). :)

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      M 1 Reply Last reply
      0
      • M monafr81

        I am working on a small game , and i have a problem -- when the user win a message box appear asking him if he want to play again if he answered -yes- the form must be shown again as it was in the beginning of the game , and i do not know how to reload the form :confused: thanks , Mona

        LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

        N Offline
        N Offline
        Nisar Inamdar
        wrote on last edited by
        #3

        :rose:Hi Mona, you do one thing..... Create one function which loads the form and then recall it . example--------- MessageBox.Show("Are you want to play Again??????","Play Game",MessageBoxButtons.YesNo)==DialogResult.Yes) { ///call the functio here........... } Nisar Inamdar

        M 1 Reply Last reply
        0
        • N Nisar Inamdar

          :rose:Hi Mona, you do one thing..... Create one function which loads the form and then recall it . example--------- MessageBox.Show("Are you want to play Again??????","Play Game",MessageBoxButtons.YesNo)==DialogResult.Yes) { ///call the functio here........... } Nisar Inamdar

          M Offline
          M Offline
          monafr81
          wrote on last edited by
          #4

          thank you Nisar Inamdar for your replay . i do a method witch create an instant from the form and call it and hide the current form ,and it works . but i have a question when i hide the current form every time the user win or lose the form still exists ,do you think that is over load in memory , and bad performance , i do not know i am asking thanks again for your Useful Replay :) Mona ,

          LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

          P 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, AFAIK you can load a form only once. But you can show and hide it many times using either Show()/Hide() methods or setting Visible property true/false. Apart from that, you could create a new instance of your form, which would give you its initial state automatically (wanted or not). :)

            Luc Pattyn


            try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


            M Offline
            M Offline
            monafr81
            wrote on last edited by
            #5

            thank you Luc Pattyn for your replay I do an instance in a method and hide the current form ,and it works , but i think when i hide the current form to call the new instance that i make an over load in memory because the current form is still exists . what do you think , How can i close the current form to cal its new instance ?? thanks again :) Mona

            LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

            L 2 Replies Last reply
            0
            • M monafr81

              thank you Luc Pattyn for your replay I do an instance in a method and hide the current form ,and it works , but i think when i hide the current form to call the new instance that i make an over load in memory because the current form is still exists . what do you think , How can i close the current form to cal its new instance ?? thanks again :) Mona

              LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

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

              why would you do that ? it is one or the other: 1. create a single instance, and now loop {initialize variables, show, hide} until app exits OR 2. loop {create an instance, show, close } until app exits it does not make sense to create a new instance, while a previous one is still around (hidden instead of closed). :)

              Luc Pattyn


              try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


              M 1 Reply Last reply
              0
              • L Luc Pattyn

                why would you do that ? it is one or the other: 1. create a single instance, and now loop {initialize variables, show, hide} until app exits OR 2. loop {create an instance, show, close } until app exits it does not make sense to create a new instance, while a previous one is still around (hidden instead of closed). :)

                Luc Pattyn


                try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                M Offline
                M Offline
                monafr81
                wrote on last edited by
                #7

                Sorry Luc Patty , I do not understand you , ok lets go slowly first : the user choose new game > The PlagGame Form Will Be shown(By Calling The Create Method witch create an instance from PlayGame Form). Second : the user Win Or Lose a Message Box Appear And Asking Him If He Want Play again ??-the PlayGame Form Still Exist - third: in this step i need to ReShow the PlayGame Form to looks like an other new game if i hide the current PlayGame form i need than to call it again with out create another instance How can I ???? sorry I know that my question may be bored :-O thanks any way Mona

                LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

                1 Reply Last reply
                0
                • M monafr81

                  thank you Luc Pattyn for your replay I do an instance in a method and hide the current form ,and it works , but i think when i hide the current form to call the new instance that i make an over load in memory because the current form is still exists . what do you think , How can i close the current form to cal its new instance ?? thanks again :) Mona

                  LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

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

                  Adding to my previous reply: you may find it difficult to organize the looping in a single form; the natural solution is to have two form classes, the main one organizing the looping (and maybe showing highest scores, or whatever), the second one representing a single game. So now the app would: create and show a main form, then loop over the following steps { create a game form, show it (maybe as a dialog) (and maybe you want to temporarily hide the main form) let the game run, when the game is done, make mainform visible again (if hidden), and close the game form } As I said before you could reuse the game form (by hiding, not closing it), but I see no real advantage here, since now you must reinitialize the game form explicitly for consecutive runs of the game. :)

                  Luc Pattyn


                  try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                  M 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Adding to my previous reply: you may find it difficult to organize the looping in a single form; the natural solution is to have two form classes, the main one organizing the looping (and maybe showing highest scores, or whatever), the second one representing a single game. So now the app would: create and show a main form, then loop over the following steps { create a game form, show it (maybe as a dialog) (and maybe you want to temporarily hide the main form) let the game run, when the game is done, make mainform visible again (if hidden), and close the game form } As I said before you could reuse the game form (by hiding, not closing it), but I see no real advantage here, since now you must reinitialize the game form explicitly for consecutive runs of the game. :)

                    Luc Pattyn


                    try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                    M Offline
                    M Offline
                    monafr81
                    wrote on last edited by
                    #9

                    of course you are Right ,and i did what you said when the user finish close the game form an return to the main form . but i do not want to return to the main form again after finishing the game , i want the game form to reshow again as if it reloaded ,that is the problem . :^) Mona

                    LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

                    L 1 Reply Last reply
                    0
                    • M monafr81

                      of course you are Right ,and i did what you said when the user finish close the game form an return to the main form . but i do not want to return to the main form again after finishing the game , i want the game form to reshow again as if it reloaded ,that is the problem . :^) Mona

                      LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

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

                      The main form can organize that without being visible. And as I said before, the game form can either be reused or be replaced by a new instance (that would cause some flickering I guess). :)

                      Luc Pattyn


                      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                      1 Reply Last reply
                      0
                      • M monafr81

                        thank you Nisar Inamdar for your replay . i do a method witch create an instant from the form and call it and hide the current form ,and it works . but i have a question when i hide the current form every time the user win or lose the form still exists ,do you think that is over load in memory , and bad performance , i do not know i am asking thanks again for your Useful Replay :) Mona ,

                        LA ELAH ELA ALLAH MOHAMED RASOL ALLAH

                        P Offline
                        P Offline
                        PhilDanger
                        wrote on last edited by
                        #11

                        I believe you can do a Form.Close() and then a Form.Dispose() in order to clean up the memory, instead of having the form stick around w/ Form.Hide.

                        M 1 Reply Last reply
                        0
                        • P PhilDanger

                          I believe you can do a Form.Close() and then a Form.Dispose() in order to clean up the memory, instead of having the form stick around w/ Form.Hide.

                          M Offline
                          M Offline
                          Martin 0
                          wrote on last edited by
                          #12

                          Hello, As the Close method allready calls Dispose, the additional Dispose call is not usefull and could also lead to an Exception!If the GC is faster then you ;)

                          All the best, Martin

                          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