Listing 1

/// <summary>
/// This method is an overload of the "Activate()" method on the
/// base class System.Windows.Forms.Form.
/// </summary>
public void Activate(string[] args)
{
    // Call the Activate method on the base class
    this.Activate();

    // Copy the parameters into a local parameter array
    _parmArray = args;

    // Bind to the parameter array
    this.listBoxParms.DataSource = _parmArray;
}

Listing 2

/// <summary>
/// The main entry point for the application.
/// </summary>
internal static void Main(string[] args)
{
    // Get the URI that was used to activate the ClickOnce application
    Uri uri = ApplicationDeployment.CurrentDeployment.ActivationUri;

    // If the application was launched via URI, process the parameters
    // that came in on the querystring.  If this instance was launched
    // from the start menu, the following block will be skipped.
    if (uri != null && uri.Query != string.Empty)
    {
        // Pull the "Query" section (the question mark and onward) out of the URI
        string _urlParameters = uri.Query;

        // Strip off the question mark at the beginning of the parameters string
        _urlParameters = _urlParameters.Remove(0, 1);

        // Parse the string at the "&" sign and replace the arguments
        // string array with url parameter string.
        // This will now be passed along to the program as command line arguments.
        args = _urlParameters.Split(new char[] { '&' });
    }

    // Run the application
    (new Program()).Run(args);
}

Listing 3

/// <summary>
/// Override of the OnCreateMainForm method that is inherited from
/// WindowsFormsApplicationBase.
/// </summary>
protected override void OnCreateMainForm()
{
    // The URL querystring parameters arrive at the application
    // as command line arguments (see static void Main below).
    // Create a local string array sized to the number of arguments
    string[] args = new string[this.CommandLineArgs.Count];

    // Copy the command line arguments to the array
    this.CommandLineArgs.CopyTo(args, 0);

    // Create a new instance of the ExampleForm form
    this.MainForm = new ExampleForm();

    // Cast the application's MainForm as an ExampleForm and
    // call the Activate method on it, passing the arguments
    ((ExampleForm)MainForm).Activate(args);
}

Listing 4

/// <summary>
/// This custom event handler method fires when
/// WindowsFormsApplicationBase.StartupNextInstance is called,
/// which is whenever the application is running and a new instance
/// of it is invoked
/// </summary>
/// <param name="sender"></param>
/// <param name="e">
/// Container for the command line arguments passed
/// to the new instance of the application
/// </param>
private void Program_StartupNextInstance(object sender,
StartupNextInstanceEventArgs e)
{
    // Create a local string array sized to
    // the number of command line arguments
    string[] args = new string[e.CommandLine.Count];

    // Copy the arguments to the array
    e.CommandLine.CopyTo(args, 0);

    // Activate our main form, passing the command line arguments to it
    ((ExampleForm)MainForm).Activate(args);
}

Listing 5

/// <summary>
/// Public constructor.  Calls the constructor on the base class,
/// Sets the event handler for secondary instances, and initializes
/// application properties.
/// </summary>
public Program() : base()
{
    // Add an event handler that will fire when a new instance is 
    // launched while the application is already running
    base.StartupNextInstance +=
	new StartupNextInstanceEventHandler(Program_StartupNextInstance);

    // Set IsSingleInstance to true to keep a new instance from launching
    // if the application is already running
    this.IsSingleInstance = true;
}

Listing 6

<head>
</head>
<body>
<a href="http://localhost/ClickOnceWindowsFormsApplication/
ClickOnceWindowsFormsApplication.application?OneParameter">
    Send One Parameter
</a>
<br>
<a href="http://localhost/ClickOnceWindowsFormsApplication/
ClickOnceWindowsFormsApplication.application?Parameter1&Parameter2">
    Send Two Parameters
</a>
</body>