[英]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.