如何同时从多个文本框中获取值

本文关键字:获取 文本 何同时 | 更新日期: 2023-09-27 18:25:31

我有一个表单,上面有许多文本框供用户输入数据。问题是,我不知道如何从框中获取值!

用户按下"保存"来保存所有值,所以我有一个"保存"这些信息的过程,但正如所说,我不知道如何提取值。我找了一下,没有找到能治好的。以下是c#:中的一些代码

// this is the procedure i want to use the value in
public static save()
{
    MessageBox.Show(trackBoxString);
}
// the event handler. trackBoxString is a public static string so that I could access it from                       different procedures
private void trackBox_TextChanged(object sender, EventArgs e)
{
    trackBoxString = trackBox.Text;
}

这只会打开一个空白的消息框

要求的更多代码

public static raceBoxString=";public static trackBoxString=";

    static void saveSetup()
    {
        try
        {
            string server = "localhost";
            string database = "*****";
            string uid = """""""";
            string password = """"""";
            MySqlConnection connection;
            string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password;
            connection = new MySqlConnection(connectionString);
            connection.Open();
            connection.Close();
            MessageBox.Show(trackBoxString);
        }
        catch (MySqlException ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

private void raceBox_TextChanged(对象发送方,EventArgs e){raceBoxString=raceBox.Text;}

    private void trackBox_TextChanged(object sender, EventArgs e)
    {
        trackBoxString = trackBox.Text;
    }

如何同时从多个文本框中获取值

ok,我将trackBox.Text移动到保存按钮事件处理程序中,出现错误。但当我保存并重新打开程序时,它很好,所以我认为windows有一点时间!谢谢你的帮助

错误为;

An object reference is required for the non-static field, method, or property