how to lock controls on other forms with out closing last form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinu jose

    how to lock controls on other forms with out closing last form?

    i have just started to create a software. in it using menu i goes form one form to another to create an user id and password for ordinary users by admin user. so with out canceling or entering fields in the last form i dont need control to go to previous form or any other form.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    When you open your new form, open it with ShowDialog instead of Show. This should prevent the user from interacting with the parent form until the child form is closed.

    Here's an example... built on an application with two buttons.

    Code:
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                ChildForm newForm = new ChildForm();
                newForm.Show();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                ChildForm newForm = new ChildForm();
                newForm.ShowDialog();
            }
        }
    
        public class ChildForm : Form
        {
            public ChildForm()
            {
            }
        }
    Clicking the first button opens the child form and lets you interact with the parent form, Form1. Clicking the second button opens the child form with ShowDialog, which prevents you from interacting with Form1.

    Hope that helps!

    Comment

    Working...