How to update the main form without creating another instance

402 views Asked by At

I currently have two forms, which are the main form and the login form. My main form is my Application.Run(); and my login form is just a dialog box. I have already created a function for the reloading of data. My problem is if i log out of my main form, then login again, the main form would not automatically refresh. I have placed my refresh function on the form_load event. I tried creating a button for the refresh and its working just as I wanted it to. How can I make my refresh function automatically change once I login another user?

This is on my program.cs:

   Application.Run(new Main_Form());

This is whats of inside my main form:

public partial class Main_Form : Form
{
    Login log = new Login();
}

private void Main_Form_Load(object sender, EventArgs e)
{            
    log.ShowDialog();
}
private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
{
    DialogResult dialogResult = MessageBox.Show("Are you sure you want to logout?", "Logout", MessageBoxButtons.YesNo);
    if (dialogResult == DialogResult.Yes)
    {
        spms.classes.FormProvider.MainMenu.Hide();
        log.uname.Text = ("");
        log.pwd.Text = ("");
        log.ShowDialog();
        log.uname.Focus();
    }
}
2

There are 2 answers

0
fedab On

When you close your login window:

YourDialog dialog = new YourDialog(...);

if(dialog.DialogResult == DialogResult.OK) //logged in successful
{
  ...
  YourRefreshButton_Click(...);
}

For your Dialog you have to set this.DialogResult = DialogResult.OK for the login button or your controls if you logged in.

0
Cullub On

Play with the .Visible property:
logoutToolStripMenuItem.Visible = false; //make it invisible