简体   繁体   English

键入numericupdown时,光标向左移动

[英]Cursor moves to left when typing in numericupdown

I have a numeric up down that has some value. 我有一个有价值的数字。 When I am changing this value from keyboard, after clicking of first key cursor moves to left from the entered value. 当我从键盘更改此值时,单击第一个键后,光标将从输入的值移到左侧。 For example, if I am entering '1', then cursor moves left from '1' not right to '1'. 例如,如果我输入“ 1”,则光标从“ 1”向左移动而不是“ 1”向右移动。

I have done some code on value changed event. 我已经完成了一些关于值更改事件的代码。

 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);
            }
        }

How can I solve this problem? 我怎么解决这个问题?

i think the problem is that when you are accessing the Value, the text is evaluated, which for some reason sometimes adjusts the text and the cursor then moves. 我认为问题在于,当您访问值时,将对文本进行评估,由于某种原因,有时会调整文本,然后光标会移动。

Maybe try and access the Text, not the Value. 也许尝试访问文本,而不是值。 I had a similiar problem (in TextChanged handler though) and instead of access numericUpDown1.Value, i do decimal.Parse(numericUpDown1.Text) and it stops moving the cursor. 我有一个类似的问题(虽然在TextChanged处理程序中),而不是访问numericUpDown1.Value,而是执行decimal.Parse(numericUpDown1.Text)并且它停止移动光标。

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

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