我如何给x赋值 [英] How can i give a value for x

查看:123
本文介绍了我如何给x赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我确实对x的值存有疑问.我想制作一个间隔x的计时器,该间隔x等于textbox1中出现的值.我应该使用什么代码?

Hi guys ,
i do have a problem with putting a value for x. I want to make a timer with interval x that will equal to value appeard in textbox1 . What code should i use ?

推荐答案

由于您在文本框中有一个要用作计时器间隔的值,因此需要将该文本值转换为一个整数,然后将其分配给计时器值.例如,您可以这样操作:

Since you have a value in a text box that you want to use as the timer interval, you need to convert that textbox value to an integer before assigning it to the timer value. For example, you could do it like this:

TextBox1.Text = RandX.Next(195, 205);
int timerNumber = Convert.ToInt32(TextBox1.Text);
yourTimer.Interval = timerNumber;


更新
根据下面的注释,这就是您的代码的外观:


Update
Based upon the comments below, this is how your code should look:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim RandX As New Random

    TextBox1.Text = RandX.Next(195, 205)
    Dim timerNumber As Integer = Convert.ToInt32(TextBox1.Text)
    Timer2.Interval = timerNumber

End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    mouse_event(mouseclickdown, 0, 0, 0, 0)
    mouse_event(mouseclickup, 0, 0, 0, 0)
End Sub


但是要注意的一件事是,假定Timer2已在运行.那可能不是您想要的.如果不是,您应该在Timer2运行之后停止它,并在Timer1中设置间隔后启动它.像这样的东西:


The one thing to pay attention to, though, is that Timer2 is assumed to already be running. That might not be what you want. If not, you should probably stop Timer2 after it runs and start it once you set the interval in Timer1. Something like this:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim RandX As New Random

    TextBox1.Text = RandX.Next(195, 205)
    Dim timerNumber As Integer = Convert.ToInt32(TextBox1.Text)
    Timer2.Interval = timerNumber
    Timer2.Start()

End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    mouse_event(mouseclickdown, 0, 0, 0, 0)
    mouse_event(mouseclickup, 0, 0, 0, 0)
    Timer2.Stop()
End Sub


尝试
延迟TextChanged事件的自定义文本框 [ ^ ]
http://www.dotnetperls.com/timer [ http://www.c-sharpcorner.com/uploadfile/mahesh/workingwithtimercontrolincsharp11302005054911am/workingwithtimercontrolincsharp. /a> [ ^ ]
Try
Custom TextBox that Delays the TextChanged Event[^]
http://www.dotnetperls.com/timer[^]
http://www.c-sharpcorner.com/uploadfile/mahesh/workingwithtimercontrolincsharp11302005054911am/workingwithtimercontrolincsharp.aspx[^]


这篇关于我如何给x赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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