简体   繁体   English

如何在C#WPF中将20%添加到文本框值

[英]How can I add 20% to a textbox value in C# WPF

In my WPF application I want a textbox that will add on a 20% to the users input value. 在我的WPF应用程序中,我想要一个文本框,该框将为用户输入值增加20%。

For example if users input is £85.00 then it should show £102.00. 例如,如果用户输入为£85.00,则应显示£102.00。

How can I achieve this? 我该如何实现? Thanks. 谢谢。

    <TextBox LostFocus="JobPrice_LostFocus" materialDesign:HintAssist.Hint="Price" Width="250" Name="JobPrice" PreviewTextInput="JobPrice_PreviewTextInput" />

You can try this c# code: 您可以尝试以下C#代码:

private void TextBox1_LostFocus(object sender, RoutedEventArgs e)
    { 
        decimal CalculatedPrice = decimal.Parse(TextBox1.Text) * 20 / 100 + decimal.Parse(TextBox1.Text);
        TextBox1.Text = CalculatedPrice.ToString();            
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM