我想在其他表单中显示我当前的用户名....例如:-show用户名每个表单使用标签 [英] I want show my current username inside the other forms....eg:-show user name every forms using label

查看:86
本文介绍了我想在其他表单中显示我当前的用户名....例如:-show用户名每个表单使用标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在其他表单中显示我当前的用户名....例如:-show用户名每个表单使用标签

解决方案

有很多方法要做到这一点:



1)您可以在每个表单中创建一个属性,该属性在创建时设置(或构造函数的一部分)

2)你可以在你的用户类中创建一个静态方法,它返回当前登录的用户名(或当前登录的用户)。

3)你可以让你的用户类成为单例,返回一个唯一的用户实例并从那里获取所需的信息。



可能我会使用第二种或第三种方法,具体取决于其余方法你的申请工作。例如,如果您有一个管理员模式可以访问多个用户,则不能为您的用户使用单例模式。



第一种方法效果很好,但它要求您确保将其传递到每个表单,并且如果一个表单注销用户会使其变得困难 - 可能需要通知所有其他表单。


If It It是 WinForm

然后使用 MDI容器并在控件中显示不需要在每页显示。



如果是 WebForm

然后使用母版页并在控件中显示无需在每个页面中显示只需继承表单中的主模板。



ELSE



在load事件上创建表单并编写代码以添加标签控件运行时和显示用户名

现在,只需继承所有表格中的表格




快乐编码!

:)

如果是WebForm,



a)继承母版页,在母版页中使用以下控件。



在母版页中

 <   asp:LoginName     ID   =  LoginName1    runat   =  server    /  >  
< asp:LoginStatus ID = LoginStatus1 runat = server / >







b)如果您没有继承母版页,请在会话中设置用户名&在每个页面中从会话中获取用户名。



如果是Windows应用程序,请检查解决方案 OriginalGriff。


i want show my current username inside the other forms....eg:-show user name every forms using label

解决方案

There are a number of ways to do this:

1) You could have a property in each form which is set when it is created (or part of the constructor)
2) You could create a static method in your user class which returns the current logged in user name (or the current logged in user).
3) You could make your user class a singleton, which returns the one-and-only user instance and get the required information from there.

Probably, I would use the second or third method, depending on how the rest of your application works. If you have an Admin mode which accesses multiple users for example, you can''t use a singleton pattern for your user.

The first method works well, but it requires you to make sure you pass the into through to each form, and can make it difficult if one form logs out the user - all the other forms may need to be notified.


If It is a WinForm
then use MDI Container and show there in a control no need to show in each page.

If It is a WebForm
then use Master page and show there in a control no need to show in each page just inherit master template in your form.

ELSE

create a form and write code on load event to add label control runtime and show username inside
and now, just inherit that form in all forms


Happy Coding!
:)


If WebForm ,

a) Inherit master page, in master page use following controls.

In master page

<asp:LoginName ID="LoginName1" runat="server" />
                <asp:LoginStatus ID="LoginStatus1" runat="server" />




b) If you are not inheriting master page then set user name in session & in each page get user name from session.

If Windows Application, Check solution posted by "OriginalGriff."


这篇关于我想在其他表单中显示我当前的用户名....例如:-show用户名每个表单使用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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