Hi everyone,

I want to know if its possible to do the following: I have 2 users and 2 forms. When user A (Admin) logs in on the Log In form, the Main Form appears with ALL its buttons enabled (For editing purposes). BUT when user B (Normal user) logs in the SAME Main From appears BUT the editing buttons are then disabled...

How can I go about this?

All I have at the moment is this:

In the logging in form

private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text == "Admin" && textBox2.Text == "Admin")
            {
                //Load main form

                MainForm f = new MainForm();
                f.ShowDialog();
                //f.Disable(button1);
            }

            else if(textBox1.Text == "User" && textBox2.Text == "User")
            {
                //Load main form with disabled buttons

                MainForm f = new MainForm();
                f.ShowDialog();
                //f.Disable(button1);
            }

            else if (textBox1.Text != "Admin" && textBox2.Text != "Admin")
            {
                MessageBox.Show("Please try logging in correctly for security purposes.");
            }

            else if (textBox1.Text != "User" && textBox2.Text != "User")
            {
                MessageBox.Show("Please try logging in correctly for security purposes.");
            }
        }
Member Avatar for iamthwee

Best to have two forms rather than suppressing textboxes and fields, it could get messy as your application grows. That's my personal opinion.

If you must use one form you can make the Admin controls unique, maybe have them in a panel. Now it's a simple matter of making the panel disabled and invisible to disable the the admin controls.

Hi Guys, thanks for the replies. All I did was to alter the load function of the form with Admin and User security settings. So if a Admin is logging in the buttons are all set to enabled. And if the User is logging in the buttons are disabled. Here is the simple code.

Thanks again!

private void MainForm_Load(object sender, EventArgs e)
{
    dataGridView1.DataSource = _HogHouse;

        //Read the current available data in the list that has been saved previously
        _HogHouse.ReadDataFromFile();

        if (Globals.mSecurityLevel == 'U')
        {
            button1.Enabled = false;
            button2.Enabled = false;
        }
        else if (Globals.mSecurityLevel == 'A')
        {
            button1.Enabled = true;
            button2.Enabled = true;
        }
}  
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.