使用标签值作为定时器间隔的值

Use label value as the value for timer interval

在 visual basic .net 中是否可以使用 label1.text 作为 timer1.interval 的值?

我尝试了以下方法,不幸的是它不起作用。

Dim Try_Interval As Integer = My.Settings.Error_Millisec
Int32.TryParse(frmSettings.Lbl_Error_Millisec_Fin.Text, Try_Interval)

它说

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll

Additional information: Value '0' is not a valid value for Interval. Interval must be greater than 0.

我也试过将它存储在 my.settings 中,如下面的代码

Dim Try_Max As Integer = Convert.ToDouble(My.Settings.Error_Try)
Dim Try_Interval As Integer = My.Settings.Error_Millisec

有什么建议吗?

您可以得到间隔设置如下:

    Dim timerValue As Integer
    Integer.TryParse(timerLabel.Text, timerValue)
    Timer1.Interval = timerValue

Int32.TryParse在可以成功解析字符串为Int32时初始化int参数,否则为0。所以要么是因为格式不正确导致无法解析字符串,要么是"0"。它的价值是多少?

The value frmSettings.Lbl_Error_Millisec_Fin.Text is 0, take note that I've taken that from another form.

Timer.Interval Property:

An Int32 specifying the number of milliseconds before the Tick event is raised relative to the last occurrence of the Tick event. The value cannot be less than one.

因此请指定一个值为 >= 1