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. Get parameters in Windows Forms App

Get parameters in Windows Forms App

Scheduled Pinned Locked Moved C#
questionwinforms
4 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.
  • B Offline
    B Offline
    blackjack2150
    wrote on last edited by
    #1

    Hi. How can I read command line parameters used to call a Windows Form Application? I use VS2005 to create a new Windows application. The autogenerated Program.cs fle looks like this: .... static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainFrm()); } } .... Shouldn't the Main method header include a parameter for arguments? Can I add it by hand? Are there any other options? Thanks.

    A 1 Reply Last reply
    0
    • B blackjack2150

      Hi. How can I read command line parameters used to call a Windows Form Application? I use VS2005 to create a new Windows application. The autogenerated Program.cs fle looks like this: .... static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainFrm()); } } .... Shouldn't the Main method header include a parameter for arguments? Can I add it by hand? Are there any other options? Thanks.

      A Offline
      A Offline
      andre_swnpl
      wrote on last edited by
      #2

      feel free to add the arguments to Main function. This wil stil work with windows forms eg. static void Main(string[] args)

      B 1 Reply Last reply
      0
      • A andre_swnpl

        feel free to add the arguments to Main function. This wil stil work with windows forms eg. static void Main(string[] args)

        B Offline
        B Offline
        bobsugar222
        wrote on last edited by
        #3

        You don't need to do that, you can just call:

        string[] args = Environment.GetCommandLineArgs();

        FYI, args[0] is the app file name.

        B 1 Reply Last reply
        0
        • B bobsugar222

          You don't need to do that, you can just call:

          string[] args = Environment.GetCommandLineArgs();

          FYI, args[0] is the app file name.

          B Offline
          B Offline
          blackjack2150
          wrote on last edited by
          #4

          Thanks for the tip.

          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