如何将声音添加到文本框或按钮 [英] how to add sound to textbox or button
问题描述
你好我正在尝试开发聊天工具,其中我使用一个2个文本框和一个按钮1。
当用户通过单击按钮在一个文本框中输入消息时,声音将会在另一个文本框中显示消息时显示(比如textbox2)
所以你可以帮我解决问题......
如果你的声音文件是.wav文件,你可以试试这个:
< pre lang =c#> protected void button1_Click( object sender,EventArgs e)
{
byte [] result = System.IO.File.ReadAllBytes( sound.wav);
System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
ms.Position = 0 ;
System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(ms);
soundPlayer.PlayLooping(); // 播放声音文件
// 现在,在另一个文本框中显示消息
soundPlayer.Stop(); // 停止播放声音
}
如果您的音频文件不是.wav文件,请查看此处:
http://www.crowsprogramming.com/archives/58 [ ^ ]
您还可以将音频文件转换为.wav文件。
查看此音频转换软件列表 [ ^ ]。
希望这会有所帮助。
hello i''m trying to develop chat facility, in which i use one 2 textbox and one button1.
whenver the user enter the message in one textbox by clicking button, then a sound will be dispaly during the message display in another textbox(say textbox2)
so can u help me in solving the problm...
Hi,
If your sound file is a .wav file, you can try this:
protected void button1_Click(object sender, EventArgs e) { byte[] result = System.IO.File.ReadAllBytes("sound.wav"); System.IO.MemoryStream ms = new System.IO.MemoryStream(result); ms.Position = 0; System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(ms); soundPlayer.PlayLooping(); // play the sound file // now, display the message in the other textbox soundPlayer.Stop(); // stop playing the sound }
If your audio file isn''t a .wav file, then have a look here:
http://www.crowsprogramming.com/archives/58[^]
You can also convert your audio file to a .wav file.
Have a look at this list of audio conversion software[^].
Hope this helps.
这篇关于如何将声音添加到文本框或按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!