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. C# obtain values from windows form

C# obtain values from windows form

Scheduled Pinned Locked Moved C#
questioncsharpjson
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.
  • C Offline
    C Offline
    classy_dog
    wrote on last edited by
    #1

    I am writing a new C# 2010 desktop applicaton. I am using some of the exsting code in another C# 2010 application to start the new application since I will be using alot of existing code that works. I basically want to have a desktop form where the user can enter some data and return to the statement after 'Application.Run(new RejectForm());' listed below.

        static void Main(string\[\] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new RejectForm());
        }
    

    I would like to have the data that was entered in the form be available to the application at this point. Thus can you tell me the following: 1. How can I return to the location right after the Application.Run(new RejectForm()); statement? 2. How can i have the values that were entered on the windows form be available for the rest of the application to access from this point?

    R L 2 Replies Last reply
    0
    • C classy_dog

      I am writing a new C# 2010 desktop applicaton. I am using some of the exsting code in another C# 2010 application to start the new application since I will be using alot of existing code that works. I basically want to have a desktop form where the user can enter some data and return to the statement after 'Application.Run(new RejectForm());' listed below.

          static void Main(string\[\] args)
          {
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new RejectForm());
          }
      

      I would like to have the data that was entered in the form be available to the application at this point. Thus can you tell me the following: 1. How can I return to the location right after the Application.Run(new RejectForm()); statement? 2. How can i have the values that were entered on the windows form be available for the rest of the application to access from this point?

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      Not sure I understand fully, but here goes. Application.Run sets up the message loop which 'runs' the form, so when the form is closed that statement ends. Normally the application terminates there as well. If you want to do some post processing create properties or retrieval methods on the form then just access them after the Run method has completed. When main() ends, so does your application.

      Regards, Rob Philpott.

      1 Reply Last reply
      0
      • C classy_dog

        I am writing a new C# 2010 desktop applicaton. I am using some of the exsting code in another C# 2010 application to start the new application since I will be using alot of existing code that works. I basically want to have a desktop form where the user can enter some data and return to the statement after 'Application.Run(new RejectForm());' listed below.

            static void Main(string\[\] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new RejectForm());
            }
        

        I would like to have the data that was entered in the form be available to the application at this point. Thus can you tell me the following: 1. How can I return to the location right after the Application.Run(new RejectForm()); statement? 2. How can i have the values that were entered on the windows form be available for the rest of the application to access from this point?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        static void Main(string[] args)
        {
        using (var f = new RejectForm())
        {
        if (DialogResult.OK == f.ShowDialog())
        {
        string someValue = f.TheValue;
        }
        else
        {
        // Cancel?
        }
        }
        }

        You'd need public properties in your RejectForm, similar to the code below;

        public class RejectForm: Form
        {
        public string TheValue
        {
        get { return theValueTextBox.Text; }
        }
        }

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        C 1 Reply Last reply
        0
        • L Lost User

          static void Main(string[] args)
          {
          using (var f = new RejectForm())
          {
          if (DialogResult.OK == f.ShowDialog())
          {
          string someValue = f.TheValue;
          }
          else
          {
          // Cancel?
          }
          }
          }

          You'd need public properties in your RejectForm, similar to the code below;

          public class RejectForm: Form
          {
          public string TheValue
          {
          get { return theValueTextBox.Text; }
          }
          }

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          C Offline
          C Offline
          classy_dog
          wrote on last edited by
          #4

          How would you incorporate the code you listed above in the windows form and then have the code return to the main method?

          L 2 Replies Last reply
          0
          • C classy_dog

            How would you incorporate the code you listed above in the windows form and then have the code return to the main method?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            classy_dog wrote:

            How would you incorporate the code you listed above in the windows form

            The first part goes into "Program.cs"; you can see the Main-method. The second part of the code goes in the form you're trying to show.

            classy_dog wrote:

            and then have the code return to the main method?

            That would happen automatically; when an application is run, the Main-method is executed. The code as presented would display a form (modal), and continue execution on the line after the "ShowDialog" call, as soon as the form closes.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            C 1 Reply Last reply
            0
            • L Lost User

              classy_dog wrote:

              How would you incorporate the code you listed above in the windows form

              The first part goes into "Program.cs"; you can see the Main-method. The second part of the code goes in the form you're trying to show.

              classy_dog wrote:

              and then have the code return to the main method?

              That would happen automatically; when an application is run, the Main-method is executed. The code as presented would display a form (modal), and continue execution on the line after the "ShowDialog" call, as soon as the form closes.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              C Offline
              C Offline
              Caldazar87
              wrote on last edited by
              #6

              There is one more thing to that. You would have to put

              DialogResult.OK;

              when you want to close Form, in order to

              DialogResult.OK == f.ShowDialog()

              be true. Best regards,

              1 Reply Last reply
              0
              • C classy_dog

                How would you incorporate the code you listed above in the windows form and then have the code return to the main method?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                As specified in above comment, I neglect to mention I'm assuming an "OK-button" on your form, with the property "DialogResult" set to "OK".

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                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