使用用户控件登录到主表单 [英] use user control for login to main form

查看:76
本文介绍了使用用户控件登录到主表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends
我创建了一个带有2个文本框的用户控件,用于输入UserId和密码,以及一个用于登录的按钮.然后将其放在表单中以登录到主表单.
如何:登录成功后关闭登录表单并显示主表单?
感谢

Hi Friends
i created a user control with 2 textBoxes to enter UserId and password,and a button to login.and i put it in a form for login to main form.
how to: close login form when login succeed and show main form?
thanks

推荐答案

创建实例并在启动表单承包商中显示您的登录表单.如果结果不成功,请退出应用程序,或者将其放入循环中,让用户尝试3次.我给你写一个简单的书,你可以自己写另一个书.
Create instance and show your Login Form in your start up Form contractor. If the result wasn''t successful so exit the Application or you can put it in a loop for let user to try 3 times. I write you simple one, you can write another yourself.
static class Program
    {
        [STAThread]
        static void Main()
        {
            System.Windows.Forms.Application.Run(new Form1());
        }
    }





public partial class Form1: Form
{
    public Form1()
    {
         loginForm _form = new loginForm();

         if (_form.ShowDialog() == DialogResult.Cancel)
             Application.Exit()

         InitializeComponent();
    }
}




您可以在Usercontrol中创建一个委托,并在用户成功登录系统后调用该委托.

您需要以将要关闭当前表单的主表单创建函数.您先前创建的委托将指向此函数.

希望我回答了你的问题,

要进行裁判检查,请执行以下操作:从用户控件中调用父表单函数 [ ^ ]
Hi,

You can create one delegate in the Usercontrol and Invoke the delegate when user is successfully login into the system.

You need to create function in main form that will close the current form. And the delegate that you have previously created will pointing to this function.

Hope i answered your question,

For referece check : Calling parent form functions from a user control[^]


这篇关于使用用户控件登录到主表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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