Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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# 自动舔片机计算_C#_Visual Studio_Winforms - Fatal编程技术网

C# 自动舔片机计算

C# 自动舔片机计算,c#,visual-studio,winforms,C#,Visual Studio,Winforms,我正在制作自动剪辑程序,我已经有问题了。我希望我的程序能够改变点击每秒字段的用户想要的方式。所以我做了这个 private void textBoxCps_TextChanged(object sender, EventArgs e) { try { time = Convert.ToDouble(textBoxCps.Text); time = 1000 / time; Math.Round(time); } ca

我正在制作自动剪辑程序,我已经有问题了。我希望我的程序能够改变点击每秒字段的用户想要的方式。所以我做了这个

private void textBoxCps_TextChanged(object sender, EventArgs e)
{
    try
    {
        time = Convert.ToDouble(textBoxCps.Text);
        time = 1000 / time;
        Math.Round(time);
    }
    catch (Exception)
    {

    }
}
数学是正确的(我认为…)


当我尝试将1个CPS放入文本框时,它每秒点击1次,与2和3相同,但当它为4或更高时,我会得到3.80或更低的CPS。

因此操作员键入一些文本,这些文本应该表示一段时间(TimeSpan),运行开始后,您希望每次调用方法
DoMouseClicks
,直到停止运行

其中一个问题是,当您执行此过程时,您希望您的用户输入具有响应性

您应该使用其中一个windows计时器,而不是睡眠。它们有好几种,每种都有各自的优点和缺点。在您的情况下,您使用的计时器取决于您需要的精度。看

如果用户线程很忙,那么单击会有点延迟,这是一个问题吗?如果不是,最简单的方法是

要更改间隔,请执行以下操作:

TimeSpan TimerInterval
{
    get => TimeSpan.FromMilliseconds(this.timer.Interval);
    set => this.Timer.Interval = value.TotalMilliseconds;
}
我决定使用TimeSpan作为间隔时间。这样,如果在将来的版本中,您决定让操作员以秒或时间格式(“01:00”)键入间隔时间,则代码更改最小

要启动和停止计时器,请执行以下操作:

private bool IsTimerStarted
{
    get => this.timer.Enable;
    set => this.timer.Enabled = value;
}
现在我们准备好对操作员输入做出反应。你决定对TextBoxChanged采取行动。你确定要这个吗?如果操作员想要键入“1000”以指示一秒的时间间隔,会发生什么情况。他首先键入“1”,你立即开始以1毫秒的频率单击鼠标。这是你想要的吗

另一个问题:如果操作员输入错误:“10)0”,而不是“1000”

一个合适的用户界面可以让操作员通过按下一个按钮来指示他已经完成了输入时间间隔。按下按钮时,您可以阅读文本。如果出现错误,则通知操作员,如果没有,则启动计时器

另一种方法是禁用按钮,只要文本框包含无效文本。虽然这看起来不错,但缺点是操作员不知道为什么按钮未启用

private void OnButtonStart_Clicked(object sender, ...)
{
    TimeSpan intervalTime = this.ReadTextBoxInterval();
    this.TimerInterval = intervalTime;
    this.IsTimerStarted = true;

    // if desired: show the operator that the action is running
}
private void OnButtonStop_Clicked(object sender, ...)
{
    this.IsTimerStarted = false;
    // if the timer was handling event Elapsed, it is finished neatly.

    // if desired show the operator that the action is stopped.
}
我决定将操作与操作员输入的解释分开。这样,如果您决定将操作员输入从毫秒更改为秒,甚至更改时间格式(“00:01”),则代码更改最小。或者,如果您决定使用组合框而不是编辑框

TimeSpan ReadTextBoxInterval()
{
    string textBoxText = this.TextBoxInterval.Text;
    return IntervalFromMsecText(textBoxText);
}

TimeSpan IntervalFromMsecText(string intervalText)
{
    if (Double.TryParse(intervalText, NumberStyles.Any, CultureInfo.CurrentCulture,
        out double msecInterval))
    {
        // input is a proper double
        return TimeSpan.FromMilliseconds(msecInterval);
    }
    else
    {
        // invalid input. Notify the operator?
    }
}

因此,操作员键入一些应该表示一段时间(TimeSpan)的文本,在开始运行后,您希望每次调用方法
DoMouseClicks
,直到停止运行

其中一个问题是,当您执行此过程时,您希望您的用户输入具有响应性

您应该使用其中一个windows计时器,而不是睡眠。它们有好几种,每种都有各自的优点和缺点。在您的情况下,您使用的计时器取决于您需要的精度。看

如果用户线程很忙,那么单击会有点延迟,这是一个问题吗?如果不是,最简单的方法是

要更改间隔,请执行以下操作:

TimeSpan TimerInterval
{
    get => TimeSpan.FromMilliseconds(this.timer.Interval);
    set => this.Timer.Interval = value.TotalMilliseconds;
}
我决定使用TimeSpan作为间隔时间。这样,如果在将来的版本中,您决定让操作员以秒或时间格式(“01:00”)键入间隔时间,则代码更改最小

要启动和停止计时器,请执行以下操作:

private bool IsTimerStarted
{
    get => this.timer.Enable;
    set => this.timer.Enabled = value;
}
现在我们准备好对操作员输入做出反应。你决定对TextBoxChanged采取行动。你确定要这个吗?如果操作员想要键入“1000”以指示一秒的时间间隔,会发生什么情况。他首先键入“1”,你立即开始以1毫秒的频率单击鼠标。这是你想要的吗

另一个问题:如果操作员输入错误:“10)0”,而不是“1000”

一个合适的用户界面可以让操作员通过按下一个按钮来指示他已经完成了输入时间间隔。按下按钮时,您可以阅读文本。如果出现错误,则通知操作员,如果没有,则启动计时器

另一种方法是禁用按钮,只要文本框包含无效文本。虽然这看起来不错,但缺点是操作员不知道为什么按钮未启用

private void OnButtonStart_Clicked(object sender, ...)
{
    TimeSpan intervalTime = this.ReadTextBoxInterval();
    this.TimerInterval = intervalTime;
    this.IsTimerStarted = true;

    // if desired: show the operator that the action is running
}
private void OnButtonStop_Clicked(object sender, ...)
{
    this.IsTimerStarted = false;
    // if the timer was handling event Elapsed, it is finished neatly.

    // if desired show the operator that the action is stopped.
}
我决定将操作与操作员输入的解释分开。这样,如果您决定将操作员输入从毫秒更改为秒,甚至更改时间格式(“00:01”),则代码更改最小。或者,如果您决定使用组合框而不是编辑框

TimeSpan ReadTextBoxInterval()
{
    string textBoxText = this.TextBoxInterval.Text;
    return IntervalFromMsecText(textBoxText);
}

TimeSpan IntervalFromMsecText(string intervalText)
{
    if (Double.TryParse(intervalText, NumberStyles.Any, CultureInfo.CurrentCulture,
        out double msecInterval))
    {
        // input is a proper double
        return TimeSpan.FromMilliseconds(msecInterval);
    }
    else
    {
        // invalid input. Notify the operator?
    }
}
Thread.Sleep()
在WinForms中是个坏主意。使用计时器。另外,您应该在try-catch语句中使用而不是包装
Convert.ToDouble()
。Math.Round()不做任何事情,因为您不使用返回值。
Thread.Sleep()
在WinForms中是个坏主意。使用计时器。另外,您应该在try-catch语句中使用而不是包装
Convert.ToDouble()
。Math.Round()不起任何作用,因为您不使用返回值。