WPF金額計算
阿新 • • 發佈:2020-12-12
WPF金額計算 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 開發工具:VisualStudio2015 關鍵技術:WPF 作者:納茲 撰寫時間:2020年12月11日 首先進行頁面佈局,設定它所在的行與列,HorizontalAlignment="Right"水平方向向右居中,Foreground設定顏色: <TextBlock Text="吊牌價: " Grid.Column="0" Grid.Row="9" HorizontalAlignment="Right"/> <TextBox Grid.Column="1" Grid.Row="9" x:Name="txt_hangcards" Foreground="#0c0c10"/> <TextBlock Text="進價折扣:" Grid.Column="3" Grid.Row="9" HorizontalAlignment="Right"/> <TextBox Grid.Column="4" Grid.Row="9" x:Name="txt_pricerebate" Foreground="#0c0c10"/> <TextBlock Text="預設進價:" Grid.Column="0" Grid.Row="11" HorizontalAlignment="Right"/> <TextBox Grid.Column="1" Grid.Row="11" x:Name="txt_readyprice" Foreground="#0c0c10" SelectionChanged="txt_readyprice_SelectionChanged"/> SelectionChanged:文字框改變事件,輸入前面兩個文字框需要計算的資料,然後點選預設進價的文字框計算出資料。 文字框改變事件控制層程式碼: private void txt_readyprice_SelectionChanged(object sender, RoutedEventArgs e) { decimal dlhang_cards =Convert.ToDecimal(txt_hangcards.Text.ToString()); decimal dlprice_rebate = Convert.ToDecimal(txt_pricerebate.Text.ToString()); decimal decAge = Convert.ToDecimal(dlhang_cards * dlprice_rebate); txt_readyprice.Text = decAge.ToString().Trim(); } 通過獲取前面兩個文字框輸入的資料,然後計算出預設進價文字框資料最後得出資料,自動回填上去。
效果如下圖: