Sending different number of parms to form constructor

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

I have a Windows form that may be called with two parameters or three
parameters (depending on who's invoking the form). The form was programmed
so it received three parameters. How can I create an instance of the form
with just two parms?
The third parameter is a System.Drawing.Point that is only necessary when
called from one event in the program.

Thanks.
 
VM,

You can always add a new constructor to the form that takes two
parameters, and then calls the constructor that uses three parameters (using
default values for the last parameter).

If you don't have access to the code that you want to call, then you
will have to create an instance of the System.Drawing.Point structure and
pass it in.

Hope this helps.
 
when you say "called", do you mean constructed? in which case, just create two constructors for your form, such as:

public MyForm(string p1, string p2)
{
...
}
public MyForm(string p1, string p2, System.Drawing.Point p3)
{
...
}

you can call one constructor from the other with the this(...) keyword, so you can still initialise your object correctly depending on what your requirement is. for example, ctor1 can call ctor2 like this:

this(p1,p2,new System.Drawing.Point(0,0));

hth

kh
 
Back
Top