hi there!!! having trouble here, i have this main form and a password form, whats happening is that when i run my program my main form is dispalyed same with password form, (its on top of the main form), what i want is that my menustrip in the mainform to be disabled once it is runned, then once the user typed the username & password and click login then the password form will closed and the menustrip in the mainform will enable, whats happening in my code is that eventhough the user hasn't type the username & password the menustrip in the mainform is still enabled. could anyone answer me... everyone is welcome...

You can either show your login form modally. in vb6 it will be

frmLogin.Show 1 'Or vbmadal

This enables the main form, although it is visible. Another option is to disable the mainstrip, again in vb6

frmMain.Tabstrip.Enabled = False

Here's an example:

MainForm:

// Make it "public" so we can access it from LoginForm
public bool loggedIn = false;

LoginForm form2;

public MainForm()
{
   InitializeComponent();
}

private void MainForm_Load(object sender, EventArgs e)
{
    // Disable the menuStrip
    menuStrip1.Enabled = false;
    
    // Initialize Form2 and pass "MainForm" as an argument
    form2 = new LoginForm(this);
    form2.ShowDialog();

    // This code will be executed after LoginForm is closed
    if (loggedIn)
    {
        menuStrip1.Enabled = true;
    }
}

LoginForm:

MainForm form1;

public LoginForm(MainForm F)
{
    InitializeComponent();

    form1 = F;
}

private void LoginBtn_Click(object sender, EventArgs e)
{
       if ( /* username/password is correct */)
       {
            form1.loggedIn = true;
            this.Close();
       }
}

P.S: I haven't tested the code. But it'll hopefully work.

Thanks

Here's an example:

MainForm:

// Make it "public" so we can access it from LoginForm
public bool loggedIn = false;

LoginForm form2;

public MainForm()
{
   InitializeComponent();
}

private void MainForm_Load(object sender, EventArgs e)
{
    // Disable the menuStrip
    menuStrip1.Enabled = false;
    
    // Initialize Form2 and pass "MainForm" as an argument
    form2 = new LoginForm(this);
    form2.ShowDialog();

    // This code will be executed after LoginForm is closed
    if (loggedIn)
    {
        menuStrip1.Enabled = true;
    }
}

LoginForm:

MainForm form1;

public LoginForm(MainForm F)
{
    InitializeComponent();

    form1 = F;
}

private void LoginBtn_Click(object sender, EventArgs e)
{
       if ( /* username/password is correct */)
       {
            form1.loggedIn = true;
            this.Close();
       }
}

P.S: I haven't tested the code. But it'll hopefully work.

Thanks

a million thanks to you, you helped me so much... it did work...

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.