增值數在我的計劃,我有幾個texboxes和按鈕coresponding名稱(例如TextBox1中 - buttonPlus1)像圖片上的C#的WinForm在texbox
但都充滿了加載數來自文本文件。 我想寫的功能,允許我按下按鈕+並從文本框中放大(例如添加固定數字,例如100)值。到目前爲止,我已經完成:
private void buttonPlus1_Click(object sender, EventArgs e)
{
AddValue(sender,e);
}
private void AddValue(object sender, EventArgs e)
{
if (!(sender is Button))
return;
string controlName = (sender as Button).Name;
string textBoxName = controlName.Replace("buttonPlus", "textBox");
TextBox textBox = this.Controls.Find(textBoxName, false)[0] as TextBox;
int step = 100;
}
但我不知道如何從文本框中獲取值(作爲數字)並添加該步驟。有人能幫幫我嗎?我試圖通過自己在許多不同的方式來解決它,但它不工作
您可以在按鈕的'.Tag'屬性中添加對相應文本框的引用。然後你的代碼將賦值爲'(sender.Tag作爲TextBox).Value = ...' – ja72