Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 键入numericupdown时,光标向左移动_C#_Winforms_Numericupdown - Fatal编程技术网

C# 键入numericupdown时,光标向左移动

C# 键入numericupdown时,光标向左移动,c#,winforms,numericupdown,C#,Winforms,Numericupdown,我有一个数值上下,有一些价值。当我从键盘更改此值时,单击第一个键后,光标从输入的值向左移动。例如,如果输入“1”,则光标从“1”向左移动,而不是从“1”向右移动 我已经对值更改事件编写了一些代码 private void txtpendingAmount_ValueChanged(object sender, EventArgs e) { try { string result = string.E

我有一个数值上下,有一些价值。当我从键盘更改此值时,单击第一个键后,光标从输入的值向左移动。例如,如果输入“1”,则光标从“1”向左移动,而不是从“1”向右移动

我已经对值更改事件编写了一些代码

 private void txtpendingAmount_ValueChanged(object sender, EventArgs e)
        {
            try
            {
                string result = string.Empty;
                if (decimal.Parse(txtAmtDue.Text, NumberStyles.Currency | NumberStyles.Number) == 0)
                {
                    result = calculateAmount(decimal.Parse(txtamount.Text == "" ? "0" : txtamount.Text, NumberStyles.Currency | NumberStyles.Number), decimal.Parse(txtpendingAmount.Value.ToString() == "" ? "0" : txtpendingAmount.Value.ToString(), NumberStyles.Currency | NumberStyles.Number));
                }
                else
                {
                    result = calculateAmount(decimal.Parse(txtAmtDue.Text == "" ? "0" : txtAmtDue.Text, NumberStyles.Currency), decimal.Parse(txtpendingAmount.Value.ToString() == "" ? "0" : txtpendingAmount.Value.ToString("C"), NumberStyles.Currency));
                }
                if (result == "Invalid")
                {
                    txtRemAmt.Text = "0.00";
                }
                else
                {
                    txtRemAmt.Text = Convert.ToDecimal(result).ToString("C");
                }
            }
            catch (Exception ex)
            {
                CusException cex = new CusException(ex);
                cex.Show(MessageBoxIcon.Error);
            }
        }

如何解决此问题?

我认为问题在于,当您访问该值时,会对文本进行求值,出于某种原因,有时会调整文本,然后光标移动

可能尝试访问文本,而不是值。
我有一个类似的问题(在TextChanged处理程序中),我没有访问numericUpDown1.Value,而是执行decimal.Parse(numericUpDown1.Text),它会停止移动光标。

但您的问题很可能是在从右到左的区域设置中开发,并且此行为会自动由窗口继承。因此,您的实际解决方案可能比简单地切换控件上的行为更复杂;“我已将位置设置为RightToLeft=No;”…这解决了吗?没有。我的问题没有解决