我是 C# 場景的新手,所以沒有太多的知識 - 這是我的第一個專案。
我正在尋找創建一個非常基本的卡路里計數器,最終將包括其他功能。
這是我到目前為止所擁有的;

我想知道如何在單擊“添加”按鈕時從文本框中獲取值 - 這會增加總值(右下角)
我正在尋找任何提示/視頻來幫助,所以任何事情都值得贊賞。
TIA
uj5u.com熱心網友回復:
我給你做了一個簡單的實作,你可以參考一下:

using System;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
bool Flag = Int32.TryParse(textBox1.Text, out int result);//Determine if it is a number
if (textBox1.Text == "")//If it is null, falg takes true and skips the next judgment
{ Flag = true; }
else if (!Flag)
{
MessageBox.Show("Input Error");
textBox1.Text = null;
}
}
private void button1_Click(object sender, EventArgs e)
{
Int32.TryParse(textBox1.Text, out int result);
int total =result Convert.ToInt32(label3.Text);
label3.Text = total.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
label3.Text = "0";
}
}
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489222.html
