One strategy is to create an overloaded constructor for your 'Questions UserControl (but, do not delete the default Constructor !).
public Questions(Panel container, int id, string questiontext) : this()
{
lblQuestionId.Text = id.ToString();
rtbQuestion.Text = questiontext;
container.Controls.Add(this);
this.Dock = DockStyle.Top;
this.BringToFront();
}
Be aware that some think it's a bad idea in WinForms to use overloaded Constructors with parameters: [
^].
The above discussion, of course, does not cover how you access the user's response, since we don't know the how/where/what of that, yet.
If you want to go the more "standard route" of implementing Properties rather than creating an overloaded Constructor, and/or you need more run-time availability (set, get, values) of the internal state of your Controls in the UserControl:
Then, be sure you have exposed (by declaring them Public) Fields, Properties, Methods, you want a "consumer" of the UserControl (the Form, or ContainerControl, the UserControl is sited/hosted in) to have access to. For Example:
public string QuestionText
{
set { rtbQuestion.Text = value; }
get { return rtbQuestion.Text; }
}
public string AnswerText
{
get { return rtbAnswer.Text; }
}
public int QuestionId
{
set { lblQuestionId.Text = value.ToString(); }
get { return Convert.ToInt32(lblQuestionId.Text);}
}
There are other good reasons for using Properties, rather than Fields, to expose members of a Class to outside "consumers:" enforce encapsulation, etc.