如何将Textbox值转换为另一种形式 [英] How to get Textbox Values to another form

查看:81
本文介绍了如何将Textbox值转换为另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ellooo People,

我有一个学校项目,我必须在Visual Studie 2013专业制作,我不知道现在该做什么...

我的项目/问题:

我需要制作一个表格,我可以登录和

然后进入主菜单,在那里可以找到文本(顶部的行)

我已经尝试了一切,但是程序说在目录中找不到名字

我已经到了点击登录的地方我去了主页菜单(另一种形式)



欲了解更多信息,请问我



greets



Mike

Ellooo People,
I have a school project that i have to make in Visual Studie 2013 Proffesional and i dont know what to do now...
My project/Problem:
I need to make a form where i can log in and
then get to a main menu where the text ( the line in the top ) can be found
I have tried everything but the program says that the name cannot be found in the directory
I'm already to the point where when i click login i go to the main menu (Another form)

For more information please ask me

greets

Mike

推荐答案

这并不难:但你究竟是怎么做的,取决于你如何在第一时间处理登录。



就个人而言,我会首先打开主表格,然后在加载活动中打开登录表格:

It's not to difficult: but exactly how you do this depends on how you handle the login on the first place.

Personally, I would bring the main form up first, and open the login form in the Load event:
frmLogin log = new frmLogin();
if (log.ShowDialog() != DialogResult.OK)
   {
   Close();
   }

然后在登录表单中执行所有验证,然后单击确定或取消退出,具体取决于登录是否有效 - 如果不然,则上面的代码关闭应用程序。



所有你要做的就是在登录表单中添加一个属性,该表单返回登录用户名,并在主公司代码中访问它:

You then do all the validation in the login form and exit with OK or Cancel depending on if the logon works or not - if it doesn't, then the code above closes the application.

All you then have to do is add a property to the login form which returns the login user name, and access it in the main firm code:

Text = "User : " + log.UserName;


你能告诉我们你的代码片段吗? />
OriginalGriff是对的,使用属性登录表单如果你想创建一个属性的类,它将保存你想要传递的值



can you show us your code snippets?
OriginalGriff was right,using property to the log in form ur If you want create a class for property that will hold the value you want to pass

Public Class MyClass
{
public string myValue{get;set;}

}





登录表格:



Log in form:

If (textBox1.text==password and textBox2.Text==UserAccount)
{
  var cls=new myClass;//instantiate the class
  cls.myValue=textBox2.Text;//pass the value
  MainForm.ShowDialog();
}





然后是主表格



then in Main form

var cls=new myClass;
textBox3.Text=cls.myValue;


你好。当您决定创建应用程序时,请考虑以下事项:

1 - 您需要什么数据?

2 - 创建一个包含您请求数据的类:

在类中,您可以定义用于处理该类的属性,例如:

Hi there. when you are deciding for creating a application consider followings:
1-what data you need?
2-create a class that has your requested data:
In a class you can define property for working with that class such as this:
class Person
{
    public string UserName { get; set; }
    public string Password { get; set; }

    private Person()
    {
        Validate();
    }
    public Person()
    {

    }

    private void Validate()
    {
        //Here you must connect to some dataSource such as SQL server for correction of entry data
    }
}





3 - 现在你必须设计你的用户界面(表格)。

4-我想你创建一个表格两个TextBoxes和两个Button。在LogButton_Click中:



3-now you must design your UI(form).
4- I suppose you create a form that has two TextBoxes and two Button. In LogButton_Click:

public Form1()
{
    InitializeComponent();
}

private void LogInButton_Click(object sender, EventArgs e)
{
    Person person = new Person();
    person.UserName = UsernameTextBox.Text;
    person.Password = PasswordTextBox.Text;
}


这篇关于如何将Textbox值转换为另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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