简体   繁体   English

如何在不创建另一个实例的情况下更新主窗体

[英]How to update the main form without creating another instance

I currently have two forms, which are the main form and the login form. 我目前有两种形式,分别是主形式和登录形式。 My main form is my Application.Run() ; 我的主要形式是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. 我已将刷新功能放在form_load事件上。 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: 这是在我的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();
    }
}

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. 对于Dialog,必须为登录按钮或控件(如果已登录)设置this.DialogResult = DialogResult.OK

.Visible属性:
logoutToolStripMenuItem.Visible = false; //make it invisible

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将值从一种形式传递到另一种形式,而无需在C#中创建形式的新实例? - how to pass a values from one form to another form without creating new instance of a form in c#? 如何在不创建实例的情况下访问在另一个类中声明的类? - How to access a class declared inside another class without creating an instance? 如何在不创建实例的情况下从一个窗口调用另一个窗口的方法? - How to call a method from one window to another without creating an Instance? 如何从另一个子表单中关闭子表单而不关闭主表单C# - How to close a sub form from another sub form without closing main form c# 如何根据主表单的条件更新另一个表单gridviewdata? - how do I update another form gridviewdata based on condition on main form? 如何通过单击另一个表单中的按钮打开我的“登录”主表单? 并且无需再次登录 - How to open my "logged in" main form, by clicking a button from another Form? and without login again 如何将一个表单的实例传递给另一个表单 - How to pass an instance of a form to another form 如何返回父表单而不在C#Windows应用程序中创建父类的新实例 - How to come back to parent form without creating new instance of parent class in C# windows application 如何在不为form1创建新实例的情况下往返两个单独的Windows窗体 - How do I go to and fro two individual windows forms without creating new instance for form1 如何在不创建新实例的情况下根据另一个列表从列表中删除多个元素? - How to remove multiple elements from list based on another list without creating new instance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM