如何使用参数连接文本框?

时间:2019-04-18 13:00:53

标签: c#

我有两个班级:FormOne123

FormOne中,有文本框,标签和按钮代码。在123中,有与Erply数据库的连接,我必须制作登录表单以使客户端可以登录,因此我必须使用用户名连接文本框,因此,如果客户端要登录,则程序会将信息发送到如果用户名和密码正确,则错误并发回。

那么不久如何将参数“用户名”与文本框连接起来?

class FormOne
{
    private void textBox18_TextChanged(object sender, EventArgs e)
    {
        //username textbox
        //I need code in here
    }
}
class 123
{
    async public void DoItJustDoItPleaseIBegYou()
    {
        string erplyPilv = "http://**clientcode**.erply.com/api/";  //"http://***.***.***.**:****/**/"

        await VerifyUser(erplyPilv, "verifyUser", "request", "**username**", "**password**", "**clientcode**", "0.1");
    }

    public async Task VerifyUser(string url, string VerifyUser, string request, string username, string password, string clientcode, string version)
    {
        IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>()
        {
            new KeyValuePair<string, string>("request", VerifyUser),
            new KeyValuePair<string, string>("username", username),
            new KeyValuePair<string, string>("password", password),
            new KeyValuePair<string, string>("clientCode", clientcode),
            new KeyValuePair<string, string>("version", version),
        };
    }
}

2 个答案:

答案 0 :(得分:1)

您只需要将文本框中的值传递给其他类中的代码

class FormOne
{
    private void textBox18_TextChanged(object sender, EventArgs e)
    {
        123 OtherClass = new 123( );
        123.DoItJustDoItPleaseIBegYou( textBox18.text );
    }
}
class 123
{
    async public void DoItJustDoItPleaseIBegYou(string UserName)
    {
        string erplyPilv = "http://**clientcode**.erply.com/api/";  //"http://***.***.***.**:****/**/"

        await VerifyUser( erplyPilv, "verifyUser", "request", UserName, "**password**", "**clientcode**", "0.1" );
    }

public async Task VerifyUser(string url, string VerifyUser, string request, string username, string password, string clientcode, string version)
{
    IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>( )
    {
        new KeyValuePair<string, string>("request", VerifyUser),
        new KeyValuePair<string, string>("username", username),
        new KeyValuePair<string, string>("password", password),
        new KeyValuePair<string, string>("clientCode", clientcode),
        new KeyValuePair<string, string>("version", version),
    };
}

答案 1 :(得分:-4)

假设您的文本框名为textBox18(根据您的函数的名称显示为文本框),然后:

private void textBox18_TextChanged(object sender, EventArgs e)
{
   var userName = textBox18.Text;
}