0

我正在创建一个 Windows 应用程序,并且我创建了一个使用数据库进行身份验证的登录页面,因此我想在登录后将我的登录名显示为主页中的标签。我怎样才能做到。如果我想创建一个会话如何创建它?

4

4 回答 4

2

You can set your login name as below code on Form1 login button click event:

var frm2 = new Form2("set login name");
frm2.Show();

and on Form2 constructor you can use the below code:

public Form2(string s)
{
    InitializeComponent();
    label1.Text = s;
}
于 2013-11-15T07:16:39.343 回答
1

你可以这样做:

主要形式:

public class MainForm
{
   public string LoginName { get; set; }

   public void ShowChildForm()
   {
      var childForm = new ChildForm(this);
      childForm.Show();
   }
}

子表:

public class ChildForm
{
   public MainForm Parent { get; set; }

   public string LoginName 
   {
      get
      {
         return Parent.LoginName;
      }
   } 

   public ChildForm(MainForm mainForm)
   {
      Parent = mainForm;
   }
}
于 2013-11-15T07:36:19.650 回答
0

从登录表单(form1)重定向到第二个表单(form2)时,请执行以下操作 -

表格 1

 Form2 f2 = new Form2("yourLoginName");
 f2.Show();

表格 2

public partial class Form2 : Form
{
    string sname;

    public Form2(string name, string id, Form a)
    {
        sname = name;

        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        label1.Text = sname; // Set your login name on label
    }
}
于 2013-11-15T07:25:01.257 回答
0

表格一:

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 f2 = new Form2();
        f2.ShowDialog();

        MessageBox.Show(f2.transfer(true).ToString()); //Returns the Text When f2 closed 
    }

表格 2:

 public partial class Form2 : Form
{

    string textToTransfer = "";

    public Form2()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        textToTransfer = textBox1.Text;
        transfer(true);
        this.Close();
    }

    public string transfer(Boolean wantToTransfer) //You could also do this without the Boolean
    {
        if (wantToTransfer == true)
        {
            textToTransfer = "Succes";
        }
        else
        {
            textToTransfer = "nope";
        }

        return textToTransfer;
    }

看起来很多,但它不是......玩得开心:)

于 2013-11-15T07:39:15.380 回答