以不同的形式显示用户名 [英] Display Username in differnt Form

查看:76
本文介绍了以不同的形式显示用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录屏幕,用户将在其中输入他们的名字和姓氏.我希望名字和姓氏出现在每个屏幕的顶部.有人可以帮忙吗?



这是我的代码...您能告诉我如何将"loginForm"中的用户名显示为这种形式吗?

 导入 System.ComponentModel


公共  escalationForm


    私有  Sub  escalationForm_Load( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs)句柄  MyBase  .Load

        My.Computer.Audio.Play(My.Resources.Adan,AudioPlayMode.Background)
        ' 自动播放音频文件

    结束 

    私有定时器1  As  定时器

    公共  新建()

        ' 设计人员需要此调用.
        InitializeComponent()

        ' 在InitializeComponent()调用之后添加任何初始化.
        timer1.Interval =  34000 
        timer1.Enabled = 
         AddHandler  timer1.Tick, AddressOf  Timer1_Tick

    结束 
    私有  Sub  Timer1_Tick( ByVal 发​​件人 As 系统.对象 ByVal  e 如 System.EventArgs)
         Dim  f2  As   introTask2
        PrintForm1.Print()
        f2.Show()
        timer1.Enabled = 错误
        关闭()
    结束 

    私有  Sub  Timer2_Tick( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs)句柄 Timer2.Tick
        ' 显示名字,姓氏,日期和时间
        Label9.Text = "  + TimeString
        Label10.Text = "  + DateString
        Label12.Text = "  + loginForm.TextBox1.Text
        Label11.Text(-"  + loginForm)

    结束 

结束  

解决方案

将其保存在会话中;在页面加载中进行设置.

具体操作方法会因您的网站编码方法而略有不同,但是Google可以通过您选择的语言使用会话变量"来找到它.


这是最可靠的解决方案表单间协作:通过表单类实现适当的接口.

请查看我过去的回答:
如何在列表框之间复制所有项目两种形式 [ ^ ].

一些注意事项:您遭受如此肮脏的代码的折磨.诸如"label1","label2"之类的名称违反了(好的)Microsoft命名约定.您永远不要离开Designer生成的名称,而将它们重命名为某些语义名称.在大多数情况下,使用时间是一个非常糟糕的主意.更喜欢线程以免遇到麻烦. (例如,请参阅我过去的回答: C#中的计时器线程 [ ^ ].)

—SA


登录后,将用户名保存在变量中,并在要显示名称的每种形式中使用此变量.


I have a login screen where the user will input their First and Last Name. I would like the first and last name to appear at the top of each screen. Can someone help?

[EDIT]

Here is my code...could you tell me how I can display the username from "loginForm" into this form?

Imports System.ComponentModel


Public Class escalationForm


    Private Sub escalationForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        My.Computer.Audio.Play(My.Resources.Adan, AudioPlayMode.Background)
        'Automatically plays audio file

    End Sub

    Private timer1 As New Timer

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        timer1.Interval = 34000
        timer1.Enabled = True
        AddHandler timer1.Tick, AddressOf Timer1_Tick

    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim f2 As New introTask2
        PrintForm1.Print()
        f2.Show()
        timer1.Enabled = False
        Close()
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        'Displays the First Name, Last Name, Date and Time
        Label9.Text = "Time: " + TimeString
        Label10.Text = "Date: " + DateString
        Label12.Text = "First Name: " + loginForm.TextBox1.Text
        Label11.Text(-"Last Name: " + loginForm)

    End Sub

End Class

解决方案

Save it in the Session; set it in the page load.

How to do it will differ slightly depending on your web site coding method, but Google for "using Session variable" with your chosen language should find it ok.


This is the most robust solution for inter-form collaboration: implementing appropriate interface by the form class.

Please see my past answer:
How to copy all the items between listboxes in two forms[^].

Some notes: you suffer from such a dirty code. The names like "label1", "label2" violate (good) Microsoft naming conventions. You should never leave Designer-generated names, rename them to some semantic names. Using times in most cases is quite a bad idea. Prefer thread to stay out of trouble. (See, for example, my past answer here: Timer Threading in C#[^].)

—SA


After login Save username in variable and use this variable in every form where you want to display name.


这篇关于以不同的形式显示用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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