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. args in main

args in main

Scheduled Pinned Locked Moved C#
tutorialquestion
11 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.
  • N nogola

    How to use the string[] args from static void Main(string[] args) in an other void ???

    D Offline
    D Offline
    Dan Neely
    wrote on last edited by
    #2

    an other void what?

    N 1 Reply Last reply
    0
    • D Dan Neely

      an other void what?

      N Offline
      N Offline
      nogola
      wrote on last edited by
      #3

      For example, how to do this: public static void Main(string[] args) { Application.Run(new Form1()); } public void do_it() { int i; for (i=0; i

      S I 2 Replies Last reply
      0
      • N nogola

        For example, how to do this: public static void Main(string[] args) { Application.Run(new Form1()); } public void do_it() { int i; for (i=0; i

        S Offline
        S Offline
        Sean89
        wrote on last edited by
        #4

        Something like this mabey?

        string[] mainArgs;
        
        public static void Main(string[] args)
        {
        mainArgs = args;
        Application.Run(new Form1());
        }
        
        public void do_it()
        {
        int i;
        for (i=0; i
        textBox1.Text += mainArgs[i];
        }
        
        I 1 Reply Last reply
        0
        • N nogola

          For example, how to do this: public static void Main(string[] args) { Application.Run(new Form1()); } public void do_it() { int i; for (i=0; i

          I Offline
          I Offline
          Igor Velikorossov
          wrote on last edited by
          #5
          public static void Main(string[] args) 
          {
          	do_it(args);
          	Application.Run(new Form1());
          } 
          
          public static void do_it(string[] args)
          {
          	// use your args here
          }
          
          N 1 Reply Last reply
          0
          • S Sean89

            Something like this mabey?

            string[] mainArgs;
            
            public static void Main(string[] args)
            {
            mainArgs = args;
            Application.Run(new Form1());
            }
            
            public void do_it()
            {
            int i;
            for (i=0; i
            textBox1.Text += mainArgs[i];
            }
            
            I Offline
            I Offline
            Igor Velikorossov
            wrote on last edited by
            #6

            **static** string[] mainArgs;

            1 Reply Last reply
            0
            • I Igor Velikorossov
              public static void Main(string[] args) 
              {
              	do_it(args);
              	Application.Run(new Form1());
              } 
              
              public static void do_it(string[] args)
              {
              	// use your args here
              }
              
              N Offline
              N Offline
              nogola
              wrote on last edited by
              #7

              Both of these solutions dont work. It says: An object reference is required for the nonstatic field, method, or property 'WindowsApplication1.Form1.mainArgs' ...

              I 1 Reply Last reply
              0
              • N nogola

                Both of these solutions dont work. It says: An object reference is required for the nonstatic field, method, or property 'WindowsApplication1.Form1.mainArgs' ...

                I Offline
                I Offline
                Igor Velikorossov
                wrote on last edited by
                #8

                what exactly are you trying to do?

                N 1 Reply Last reply
                0
                • I Igor Velikorossov

                  what exactly are you trying to do?

                  N Offline
                  N Offline
                  nogola
                  wrote on last edited by
                  #9

                  I wanna write all the args into a textBox in the main Form (Form1)

                  N I 2 Replies Last reply
                  0
                  • N nogola

                    I wanna write all the args into a textBox in the main Form (Form1)

                    N Offline
                    N Offline
                    nogola
                    wrote on last edited by
                    #10

                    Oh I didnt see tje reply where you wrote that it has to be static, now it works, tnx!!!

                    1 Reply Last reply
                    0
                    • N nogola

                      I wanna write all the args into a textBox in the main Form (Form1)

                      I Offline
                      I Offline
                      Igor Velikorossov
                      wrote on last edited by
                      #11
                      	[STAThread]
                      	public static void Main(string[] args)
                      	{
                      		Application.EnableVisualStyles();
                      		Application.DoEvents();
                      		Application.Run(new myForm(args));
                      	}
                      
                      	public class myForm : Form {
                      
                      		public myForm(string[] args)
                      		{
                      			InitializeComponent();
                      
                      			if (args != null && args.Length > 0)
                      			{
                      				for (int i = 0; i < args.Length; i++)
                      				{
                      					this.txt.Text += args[i];
                      				}
                      			}
                      		}
                      		// leave this method for the designer
                      		private myForm()
                      		{
                      			InitializeComponent();
                      		}
                      
                      		//
                      		// rest of code
                      		//
                      
                      	}
                      
                      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