? Passing parameters to a Windows Form ?

  • Thread starter Thread starter sprungli
  • Start date Start date
S

sprungli

Hello,



Is it possible to pass parameters to a Windows Form the way it can be done
with a Web Form. I searched the VS.NET finding nothing.



Many thanks in advance.
 
I think what you want to do is use CommandLine parameters. Remember that a
WindowForm is just an .exe program. You could execute it from a command
line with parameters. You did not say what language you were using but here
is example from MSDN for VB.Net

Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String = " "
Dim commands As String = Microsoft.VisualBasic.Command()
Dim args() As String = commands.Split(separators.ToCharArray)
Return args
End Function

Lloyd Sheen
 
In addition here is sample of C# commandline processing from MSDN.

// cmdline1.cs
// arguments: A B C
using System;

public class CommandLine
{
public static void Main(string[] args)
{
// The Length property is used to obtain the length of the array.
// Notice that Length is a read-only property:
Console.WriteLine("Number of command line parameters = {0}",
args.Length);
for(int i = 0; i < args.Length; i++)
{
Console.WriteLine("Arg[{0}] = [{1}]", i, args);
}
}
}

Lloyd Sheen
 
Thank you Lloyd for your answer.

No, in fact I don't want to use the command line to pass parameters. I want
to be able to access these in the Load event of the form. In a Web Form you
access the parameters passed through the implicit Request object. Is there
anything like that in Windows Forms? How can I launch one Windows Form from
a button or a link in another Windows Form and possibly pass some parameters
(if possible at all) ?

I use C#.

TIA
 
Ok, then you want to create a constructor for the form into which you can
pass the parameters. Then when the button is clicked use that constructor
to create the form with the passed parameters. If the parameters can only
be actioned on the load, then cache them in variables and then use them
during the load event.

Lloyd Sheen
 
Back
Top