[英]Issue in displaying “-” symbol in calculator application in C# WPF
嗨,我正在尝试学习Windows Presentation Foundation WPF,并正在尝试开发最简单的应用程序Calculator。 但是当我从较小的值中减去较高的值时,在显示“-”时出现问题。 例如。 如果我做类似“ 10-20”的操作,则输出应为“ -10”,即文本框。 但是它显示“ 10-”。 最终以某种方式出现“-”。 我的文本框xaml代码如下所示:
<TextBox Height="33" HorizontalAlignment="Left" Name="outputbox"
VerticalAlignment="Top" Width="278"
FontFamily="Tahoma" FontSize="18"
FlowDirection="righttoleft" IsReadOnly="True" />
进行减法和显示的代码如下所示
if (entry1 > entry2)
{
outputbox.Text = (entry1 - entry2).ToString();
}
else
{
outputbox.Text = "-" + (entry2 - entry1).ToString();
}
在调试时,它会显示正确的字符串为“ -10”,而在文本框中显示时,它会显示字符串“ 10-”。 关于缺少什么的任何想法???
只需从TextBox中删除FlowDirection属性,您的结果就可以了。
<TextBox Height="33"
HorizontalAlignment="Left"
Name="outputbox" VerticalAlignment="Top"
Width="278"
FontFamily="Tahoma"
FontSize="18" IsReadOnly="True" />
或者,您可以指定FlowDirection="LeftToRight"
,这是TextBox的默认设置
谢谢大家 我删除了“ FlowDirection”属性,它显示了正确的“ -10”,但是文本现在显示在文本框的左侧。 因此,我使用了“ TextAlignment = right”属性,它似乎运行良好。 再次感谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.