NumericUpDown控件抛出异常错误 [英] NumericUpDown Control Throw Exception Error

查看:106
本文介绍了NumericUpDown控件抛出异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚在winform中创建了一个基本的两个NumericUpDown控件。这两个控制器执行值的递增和递减,就像我在第一个控制器中选择5一样,第二个控制器自动选择6,同样的方式递减。



I使用了这段代码:



Just created a basic two NumericUpDown control in winform. These two controller do the increment and decrement of the value, like if i choose 5 in first controller the second controller automatically choose 6, the same way in decrement.

I have used this code:

Private Sub NumericUpDown2_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown2.ValueChanged
       NumericUpDown2.Minimum = NumericUpDown2.Value + 1
   End Sub

   Private Sub NumericUpDown3_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown3.ValueChanged
       NumericUpDown3.Maximum = NumericUpDown3.Value - 1
   End Sub





然后当我使用F5运行时,我收到了Project.exe文件中出现System.StackOverflowException的异常错误,然后当我单击Break按钮时,它打开了Application.Designer.vb文件并突出显示了代码 -



Then when i run with F5, i got the exception error of "System.StackOverflowException occured in Project.exe file" , then when i click the Break button, it opened the Application.Designer.vb file and highlighting the code -

Me.MainForm = Global.ProjectLinked.PLGeneralSettings





请帮助我..



Please help me..

推荐答案

:叹息:

查看你的代码。

在ValueChanged事件处理程序中,你正在改变最小值的值大于当前值的一个 - 这样可以使控件更改值,使其适合新的限制。这会导致另一个ValueChanged事件被触发,你在那里......再次更改值,导致另一个ValueChanged事件,你在哪里...

这一直持续到你的应用程序从空间中消失并摔倒。 br $> b $ b



不要这样做。这太傻了。
:sigh:
Look at your code.
In the ValueChanged event handler, you are changing the value of the minimum value to one greater than the current value - so that causes the control to change the value so it fits in the new limits. This causes another ValueChanged event to fire, where you...change the value again, causing another ValueChanged event, where you...
This continues until your app ruins out of space and falls over.


Don't do that. It's silly.


这篇关于NumericUpDown控件抛出异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆