I have designed 3 different win forms in c#.
public partial class SLOSPR : form
{
public bool IsCallable;
public void PopulateData();
}
public partial class SLOFIX : form
{
public bool IsCallable;
public void PopulateData();
}
public partial class SPDBID : form
{
public bool IsCallable;
public void PopulateData();
}
I have declared one member variable IsCallable in every form's class and a member function PopulateData() in every form's class. It is so because, in a code segment I want to declare one variable of a form type, and want to assign an object of any of the above 3 classes and use that IsCallable variable and call PopulateData().
like this:
public form RetForm()
{
form frm=new /* constructor of any 3 forms mentioned above*/
//this function can return any of the three types which will be decided at run time.
return frm;
}
form frm=RetForm();
here i want to use IsCallable and call PopulateData().
like this:
if(frm.Iscallable)
frm.PopulateData();
Which is not possible syntactically as Iscallable and PopulateData is not member of form class
To solve this problem I extended the form class to an abstract class and declared those 3 forms from the extended class.
public abstract class EXTENDED_FORM : form
{
public bool IsCallable;
public abstract void PopulateData();
}
and changed the definition of those 3 forms like this.
public partial class SLOSPR : EXTENDED_FORM
{
public override void PopulateData()
{
/*body for SLOSPR */
}
}
public partial class SLOFIX : EXTENDED_FORM
{
public override void PopulateData()
{
/*body for SLOFIX */
}
}
public partial class SPDBID : EXTENDED_FORM
{
public override void PopulateData()
{
/*body for SPDBID*/
}
}
Now I did like this:
public EXTENDED_FORM RetForm()
{
EXTENDED_FORM frm=new /* constructor of any 3 forms mentioned above*/
//this function can return any of the three types which will be decided at run time.
return frm;
}
EXTENDED_FORM frm=RetForm();
Now I can call like this:
if(frm.Iscallable)
frm.PopulateData();
Automatically overridden PopulateData will be called.
Finally I made my purpose. But as I changed
public partial class SLOSPR : form /*[Designer generated code]*/
to
public partial class SLOSPR : EXTENDED_FORM
The GUI designer in Visual Studio gets messed up, showing the following page.
How to get rid of this, also my purpose gets fulfilled without hampering the designer???