Greg,
A form is nothing but a class. I don't have VS2003 IDE in front of me, so
I'll try peice this from my memory, but my understanding is that in VS2003,
when you add a form, it creates a default constructor for you, that looks
somewhat like
class Form1 : System.Windows.Forms.Form
{
.... some other code .. who cares ..
... some more code who cares ..
public Form1()
{
((Was there a call to InitializeComponent here? I don't remember)).
// TODO: Write your custom logic here.
}
public Form1(string doggieName) // This is where the nondefault
constructor would go.
{
}
.... some other code .. who cares ..
... some more code who cares ..
}
.... I might add, the EXACT placement is irrelevant, as long as it is within
public class Form1
{
...
}
and as long as it looks like another method at the same level as the default
constructor.
... If it is still unclear, attach your Form1.cs with your reply and I'd be
happy to modify it.
- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Greg Horwood" <(E-Mail Removed)> wrote in message
news:42F4AAC2-9423-41FB-8593-(E-Mail Removed)...
> Thanks for you reply Sahil. However, I'm still a little confused as to how
> to
> permorm this using the Visual Studio IDE. I'm glad to hear that the same
> constructor mentality exists in C#, it's just the practicalities I'm
> struggling with.
> For instance, using you Dog class, where in the output code developed by
> Visual Studio would you create this constructor? After Form1()? Or where
> the
> TODO tells you to put constructor information.
> Thanks
>
> Greg
>
> "Sahil Malik" wrote:
>
>> Greg,
>>
>> You can very easily create overloaded constructors in C#.
>>
>> So if you had a class called Dog
>>
>> public class Dog
>> {
>> private string strDoggiename = "" ;
>> public Dog() // Default constructor
>> {
>> }
>>
>> public Dog(string doggiename)
>> {
>> strDoggiename = doggiename;
>> }
>> }
>>
>> The above is a valid class that you can use as either of below.
>>
>> Dog ruffie = new Dog() ;
>>
>> or
>>
>> Dog ruffie = new Dog("ruffie") ;
>>
>> The only restriction .NET imposes compared with C++ is that, if your base
>> class did not implement a default constructor, the inherited classes must
>> explicitly call a non default constructor in their constructors. That is
>> explained over here -
>> http://dotnetjunkies.com/WebLog/sahi.../07/27986.aspx
>> ..Other than that, everything is hunky dory.
>>
>> - Sahil Malik
>> http://dotnetjunkies.com/weblog/sahilmalik
>>
>>
>>
>>
>>
>> "Greg Horwood" <(E-Mail Removed)> wrote in message
>> news:02CEAB2B-3C0A-4F9F-B245-(E-Mail Removed)...
>> > Dear All,
>> >
>> > I wish to populate various fields in an additional windows form which
>> > is
>> > triggered by the main app.
>> >
>> > Passing the information from the main app to the dialog is proving to
>> > be
>> > difficult. Obviously I don't want to alter the controls' modifiers and
>> > thus I
>> > would normally create an additional constructor (like in VC++) to take
>> > care
>> > of accepting the variables.
>> >
>> > In other words:
>> > Form2()
>> > Form2(int param1, string param2)
>> >
>> > My question is: Is this approach the normal way to go? And if so, how
>> > does
>> > one create an alternate contructor? Or is that something which belongs
>> > to
>> > C++.
>> >
>> > Any help really appreciated.
>> >
>> > Thanks
>> >
>> > Greg
>> >
>> >
>> >
>> >
>>
>>
>>