Hello,
I have a main form which displays information which the user can update by clicking an update button, this creates a form with text fields and a submit button which updates a text file when the user clicks the button.
However, the user can click the update button on the main form as many times as they want and it creates lots of the smaller form! Is there a way to allow the smaller form to be displayed while the main form is behind it, but only allow one instance of the form even if the user clicks the button again?
Loading
SamPosted Jul 3, 2007, 1:46 PM
You could just disable the Update button when it's clicked
then re-enable it when the 2nd Form closes
e.g
public partial class MainForm: Form
{
//... RAD Code
private void UpdateButton_Click(object sender, EventArgs e)
{
UpdateButton.Enabled = false;// disable button
Form2 UpdateForm = new Form2(); // create 2nd Form
UpdateForm.FormClosing += new FormClosingEventHandler(this.UpdateForm_FormClosing);
// attach event handler
UpdateForm.Show(); // shows the form
}
private void UpdateForm_FormClosing(object sender, EventArgs e)
{
UpdateButton.Enabled = true;// enable button
}
}
Posted Jul 3, 2007, 9:51 AM
Chintan DesaiPosted Jul 3, 2007, 8:41 AM
assign one Reference of small form in Main form. Before calling or creating instance of small form, check whether it is null of not.If it is null that mean its instance has not created yet,otherwise it is null.
Mahesh ChandPosted Jul 3, 2007, 8:06 AM
Drew TaylorPosted Jul 3, 2007, 7:27 AM
That sounds difficult! But I'm guessing it's not, could you show me how you would do it in code?
ManuelPosted Jul 3, 2007, 7:21 AM
Declare the smaller form as variable in your main form.
If the smaller form has to be shown, check if that variable isn't null - if it does just reset properties in that form to defaults and show that one, otherwise set that variable by creating an instance and then show it.