C
cefrancke
I have designed a generic "DataInput" form that I would like to re-use
depending on what menu item the user has chosen.
Say I have a menu with three items, where each menu item needs to
provide a form for data display and input.
Menu items: DataInputA, DataInputB and DataInputC (this is the text in
the menu)
Now if the user chooses DataInputA, I would like to create a form based
on the generic "DataInput" form (class) I already designed.
Then, at some point before displaying the new form, I want to set all
the control text, data, etc properties that are relevent to the menu
choice.
I figure, on the menu item click event, call a method to create the new
form based on the generic class. I send the title bar text, based on
menu choice.
private void subSystemsToolStripMenuItem_Click(object sender,
EventArgs e)
{
CreateDataInput("SubSystems");
}
private void CreateDataInput(String frmTitleBarText)
{
frmDataInput FormDataInput = new frmDataInput();
FormDataInput.MdiParent = this;
FormDataInput.Text = frmTitleBarText;
//Before I show the form, I need to set all the control
properties on the new form.
FormDataInput.Show();
}
Being new, I'm not sure if this approach is a good practice or even
practical.
If this approach is not too unusual, I'm not sure where to set the
properties of the new form.
Should this be in the contructor of the new form? If so, I could call a
method, from the constructor to determine what menu item is clicked and
use a Select block for each situation.
How would I pass this info to the constructor?
Or if not in the constructor, I can call a method before the Show
method (see the above code snippet) to decide how to set up the new
form, but how do I get to the "private" controls of the new form. (I
got an error saying, the control is inaccessable due to its protection
level).
Any sample code, snippets or a reference would be a big help.
TIA
depending on what menu item the user has chosen.
Say I have a menu with three items, where each menu item needs to
provide a form for data display and input.
Menu items: DataInputA, DataInputB and DataInputC (this is the text in
the menu)
Now if the user chooses DataInputA, I would like to create a form based
on the generic "DataInput" form (class) I already designed.
Then, at some point before displaying the new form, I want to set all
the control text, data, etc properties that are relevent to the menu
choice.
I figure, on the menu item click event, call a method to create the new
form based on the generic class. I send the title bar text, based on
menu choice.
private void subSystemsToolStripMenuItem_Click(object sender,
EventArgs e)
{
CreateDataInput("SubSystems");
}
private void CreateDataInput(String frmTitleBarText)
{
frmDataInput FormDataInput = new frmDataInput();
FormDataInput.MdiParent = this;
FormDataInput.Text = frmTitleBarText;
//Before I show the form, I need to set all the control
properties on the new form.
FormDataInput.Show();
}
Being new, I'm not sure if this approach is a good practice or even
practical.
If this approach is not too unusual, I'm not sure where to set the
properties of the new form.
Should this be in the contructor of the new form? If so, I could call a
method, from the constructor to determine what menu item is clicked and
use a Select block for each situation.
How would I pass this info to the constructor?
Or if not in the constructor, I can call a method before the Show
method (see the above code snippet) to decide how to set up the new
form, but how do I get to the "private" controls of the new form. (I
got an error saying, the control is inaccessable due to its protection
level).
Any sample code, snippets or a reference would be a big help.
TIA