How to make a controls compliant for winform and webform?
Posted
by Martijn
on Stack Overflow
See other posts from Stack Overflow
or by Martijn
Published on 2010-04-09T07:42:45Z
Indexed on
2010/04/09
7:53 UTC
Read the original article
Hit count: 228
c#
In my application I have methods which returns a control (checkbox, radiobutton, textbox) but I want to use the same class for my webform and winform. How can I achieve this? I was thinking about an interface, but I don't know how to implement this.
In my code I have the following methods:
public TextBox GenerateTextfield(AnswerPossibility answerPossibility)
{
TextBox textBox = new TextBox();
textBox.Tag = answerPossibility.Tag;
return textBox;
}
public Collection<ButtonBase> GenerateMultipleChoice(Collection<AnswerPossibility> answers)
{
Collection<ButtonBase> checks = new Collection<ButtonBase>();
foreach (AnswerPossibility a in answers)
{
CheckBox chk = new CheckBox();
chk.Text = a.Text;
chk.Name = "chk" + a.Id.ToString();
chk.Tag = a.Tag;
checks.Add(chk);
}
return checks;
}
How can I make this so, that I can use this methods in a win form as well in a web form?
© Stack Overflow or respective owner