Form1和Form 2之间的交互 [英] interaction Between Form1 and Form 2

查看:71
本文介绍了Form1和Form 2之间的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

盖伊。请你能帮我解决这个问题。我有Form1(使用Buttom登录),我有一个Form2(With Buttom注销)。

1.之后,用户输入他的名字,正确的密码并点击Login Buttom,Form2 st打开,Form1得到隐藏。稍后当用户注销时,Form2 Unenable和Form1再次出现,新用户kann再次登录并使用Form2。



但我的问题是我不知道找出如何使用相同的Form2。我尝试打开一个新的Form2实例。

Form1登录

Hi Guy. Please can u help me to solve this Problem. I have Form1(With Buttom Login) and i have a Form2(With Buttom logout).
1. after that the User enter his Name,zhe correct Passwort and click on the Login Buttom, the Form2 st opened and Form1 get hide. Later when the User is loging out is Form2 Unenable and Form1 appear again and the neww User kann sign in and use Form2 again.

But my Problem is that i don't find out how to use the same Form2. everithing i try open me a new Instance of Form2.
Form1 Login

private void btnLogin_Click(object sender, EventArgs e)
{
    try
    {
        UserApplication user = new UserApplication(userName);
        user.Show();

    } catch(Exception ex){
        MessageBox.Show(ex.Message);
    }
}



Form2退出


Form2 Logout

private void btnLogout_Click(object sender, EventArgs e)
 {
     try
     {
         Login in = new Login();
         in.Visible = true;

     }
    catch(Exception ex)
    {
         MessageBox.Show(ex.Message);
     }
 }



我找不到解决这个问题的可能性。我总是得到一个新的实例。你有什么想法吗?


i don't find a possibility to solve this Problem. i get always a new instance. do you have some idea?

推荐答案

参见..

http://www.daniweb.com/software-development/csharp/threads/340187/moving-between-forms [ ^ ]

http://stackoverflow.com/questions/7558651 / logout-the-main-form-and-show-the-login-form [ ^ ]
See..
http://www.daniweb.com/software-development/csharp/threads/340187/moving-between-forms[^]
http://stackoverflow.com/questions/7558651/logout-the-main-form-and-show-the-login-form[^]


是。停止这样做。

不要使用Show - 使用ShowDialog:

Yes. Stop doing that.
Don't use Show - use ShowDialog:
private void btnLogin_Click(object sender, EventArgs e)
    {
    try
        {
        UserApplication user = new UserApplication(userName);
        Hide();
        user.ShowDialog();
        Show();
        }
    catch (Exception ex)
        {
        MessageBox.Show(ex.Message);
        }
    }

并且

And

private void btnLogout_Click(object sender, EventArgs e)
    {
    Close();
    }

将为你解决。


你好朋友,

你可以使用设置。设置文件,以保存属性文件夹中存在的Form2的数据。我想这会对你有帮助。

祝你好运
Hi friend,
You can use the Settings.settings file to save you data of Form2 present in properties folder.I think this will help you.
Good luck


这篇关于Form1和Form 2之间的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆