1
我想使用只有文本框來做一個簡單的計算器。 我以爲我的代碼是正確的,但結果幾乎總是錯的。只使用文本框操作c#
這是代碼:
void TextBoxPercorsoTextChanged(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(textBoxPercorso.Text) && !string.IsNullOrEmpty(textBoxAgilitySmallVelocita.Text))
textBoxAgilitySmallTps.Text=(Convert.ToDecimal(textBoxPercorso.Text)/Convert.ToDecimal(textBoxAgilitySmallVelocita.Text)).ToString();
}
void TextBoxAgilitySmallVelocitaTextChanged(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(textBoxPercorso.Text) && !string.IsNullOrEmpty(textBoxAgilitySmallVelocita.Text))
textBoxAgilitySmallTps.Text=(Convert.ToDecimal(textBoxPercorso.Text)/Convert.ToDecimal(textBoxAgilitySmallVelocita.Text)).ToString();
}
我試圖做一些嘗試。例如,我試圖做10/5,但結果是0.5。只有10月份的結果是正確的。
你能幫助我嗎?
難道是你需要顛倒你的論點嗎? – npinti
@npinti你是對的!但我不明白爲什麼。我必須做長度/速度,所以我做了textboxLength/textboxSpeed。如果我顛倒了我的論點,結果是正確的 – Marietto
請確保您沒有交換顯示屏上的文本框,因此當您正在考慮您正在閱讀另一個字段時,您將從一個字段中讀取。 – npinti