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. Transfer parameter in main method

Transfer parameter in main method

Scheduled Pinned Locked Moved C#
question
11 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.
  • J jason_mf

    when program startup, I will give a parameter to main meth. then this parameter will transfer to MainForm(parameter of "Application.Run" method). But if program has run, how fransfer this parameter or get the MainForm?

    D Offline
    D Offline
    dan sh
    wrote on last edited by
    #2

    Do you mean you want send some values as parameters to Main? This can be done like: Goto "Project properties -> Debug -> command line arguments" and put values separated by space.

    J 1 Reply Last reply
    0
    • D dan sh

      Do you mean you want send some values as parameters to Main? This can be done like: Goto "Project properties -> Debug -> command line arguments" and put values separated by space.

      J Offline
      J Offline
      jason_mf
      wrote on last edited by
      #3

      yes. But i want to send this parameter to WindowsForm yet.

      D 1 Reply Last reply
      0
      • J jason_mf

        yes. But i want to send this parameter to WindowsForm yet.

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #4

        Well in that case, create a parameterized constructor of the form you are calling in Applicatio.Run() and send the values.

        J 1 Reply Last reply
        0
        • D dan sh

          Well in that case, create a parameterized constructor of the form you are calling in Applicatio.Run() and send the values.

          J Offline
          J Offline
          jason_mf
          wrote on last edited by
          #5

          Thanks. But you said the way can achieve at startup only. If program has run, how send parameter?

          D E 2 Replies Last reply
          0
          • J jason_mf

            Thanks. But you said the way can achieve at startup only. If program has run, how send parameter?

            D Offline
            D Offline
            dan sh
            wrote on last edited by
            #6

            jason_mf wrote:

            But you said the way can achieve at startup only. If program has run, how send parameter?

            Didnt got that.

            J 1 Reply Last reply
            0
            • J jason_mf

              Thanks. But you said the way can achieve at startup only. If program has run, how send parameter?

              E Offline
              E Offline
              Expert Coming
              wrote on last edited by
              #7

              If the program is already running you still send the parameter the same way, the constructor. The only difference is that Application.Run() won't be calling that constructor. You will have to call it yourself, how is up to you.

              The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

              J 1 Reply Last reply
              0
              • D dan sh

                jason_mf wrote:

                But you said the way can achieve at startup only. If program has run, how send parameter?

                Didnt got that.

                J Offline
                J Offline
                jason_mf
                wrote on last edited by
                #8

                Because my winform program can run only instance. So I checked in main of program class. if there is a instance in proceeding, can I get the main form of this instance? Or other way?

                E 1 Reply Last reply
                0
                • J jason_mf

                  Because my winform program can run only instance. So I checked in main of program class. if there is a instance in proceeding, can I get the main form of this instance? Or other way?

                  E Offline
                  E Offline
                  Expert Coming
                  wrote on last edited by
                  #9

                  What kind of information are you trying to pass, and when?

                  The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

                  J 1 Reply Last reply
                  0
                  • E Expert Coming

                    If the program is already running you still send the parameter the same way, the constructor. The only difference is that Application.Run() won't be calling that constructor. You will have to call it yourself, how is up to you.

                    The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

                    J Offline
                    J Offline
                    jason_mf
                    wrote on last edited by
                    #10

                    first get the form. then set property of the form. can it achieve ? But I can not get the form.

                    1 Reply Last reply
                    0
                    • E Expert Coming

                      What kind of information are you trying to pass, and when?

                      The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

                      J Offline
                      J Offline
                      jason_mf
                      wrote on last edited by
                      #11

                      Anther program will call my winform program, then open a form (is not MainForm ). the caller will send a string to my winform. when the caller calls, my winform maybe has run, or does not run.

                      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