C#请帮忙!根据TextBox中的数字发出一定数量的哔声 [英] C# Please Help! Beeps a certain number depending on number in TextBox

查看:86
本文介绍了C#请帮忙!根据TextBox中的数字发出一定数量的哔声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以,我一直在寻找方法来做到这一点,但我无法弄明白。我想创建一个Windows窗体应用程序,旁边有一个按钮和一个TextBox。最终产品应如下所示:您在TextBox中输入一个数字,然后单击
按钮。根据您输入的数字,计算机将发出多次哔声。我已经弄清楚TextBox是如何工作的以及Console.Beep方法,但我无法弄清楚这两者如何协同工作。 

Alright, so, I've been searching for days for a way to do this, but I can't figure it out. I want to create a Windows Form App with a button and a TextBox next to it. The final product should be like this: you enter in a number in the TextBox, then click the button. Depending on what number you input, the computer will beep that amount of times. I've figured out how the TextBox works and the Console.Beep method as well, but I can't figure out how the two can work together. 

我在工作Visual Studio 2017和C#。我还是新编程,这是为了学校。

I'm working in Visual Studio 2017 and with C#. I'm still new to programming and this is for school.

谢谢!

推荐答案


您输入TextBox中的数字,然后单击按钮。根据您输入的数字,计算机将发出多次哔声。我已经弄清楚TextBox是如何工作的以及Console.Beep方法,但是我无法弄清楚这两个可以如何合作


you enter in a number in the TextBox, then click the button. Depending on what number you input, the computer will beep that amount of times. I've figured out how the TextBox works and the Console.Beep method as well, but I can't figure out how the two can work together.

需要考虑的一些事项和实验:



(1)单击该按钮时,将文本框中的数字从
转换为整数,参见:



Int32.TryParse方法(String,Int32)

https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx



(2)使用(1)中的整数来控制发出嘟嘟声的

a循环的迭代次数。



(3)由于循环将执行*非常快*,因此多个连续的嘟嘟声b
将倾向于"混合"。一起到人的耳朵,听起来就像是一声嘟嘟声。

所以你可能想要在哔哔声之间发出很短的睡眠时间,这样它们就会发出不同的声音。请参阅:
$


Thread.Sleep方法(Int32)

https://msdn.microsoft.com/en-us/library/d00bd51t(v = vs.110)的.aspx
$


- Wayne

Some things to consider and with which to experiment:

(1) When the button is clicked, convert the number in the textbox
from a string to an integer, See:

Int32.TryParse Method (String, Int32)
https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx

(2) Use the integer from (1) to control the number of iterations of
a loop that issues the Beep.

(3) Since the loop will execute *very* fast, multiple successive Beeps
will tend to "blend" together to a human ear and sound like one Beep.
So you may want to issue a very short Sleep between Beeps so that they
sound distinct. See:

Thread.Sleep Method (Int32)
https://msdn.microsoft.com/en-us/library/d00bd51t(v=vs.110).aspx

- Wayne


这篇关于C#请帮忙!根据TextBox中的数字发出一定数量的哔声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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