从事件处理程序访问数组 [英] Accessing an array from an event handler

查看:83
本文介绍了从事件处理程序访问数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我目前正在处理一个包含wav文件的项目.我想使用单选按钮,以便当您单击该按钮时,从阵列中选择下一个声音文件,并在暂停1秒后播放.

我可以从加载时或当我播放声音文件时有一个按钮,特别是硬编码文件地址,但是我想使用数组来获取文件位置.

代码如下:

我设置了将值放入数组

wavfiles [6] = elemds.Tables [3] .Rows [i] .ItemArray [3] .ToString().Replace("\\","\\\\");

然后在单选按钮上单击,我认为我可以使用

private void radioButton1_CheckedChanged(对象发送者,EventArgs e)
                              {
                    
           SoundPlayer myPlayer =新的System.Media.SoundPlayer();
myPlayer.SoundLocation = @wavfiles [6];
                                    myPlayer.Play();
        }

我也曾考虑过创建一个类来保存此数组并将值存储在其中,但是我不确定该如何去做.

如果有人可以提供帮助,那将是非常可取的.

致谢

Myles

Hi,

I am working on a project with wav files at the minute. I want to use a radio button so that when you click the button the next sound file is selected from the array and played after a 1 second pause.

I can get the sound files to play from load or when i have a button and specifically hard code the file address but i would like to use the array to get the file locations.

The code is as below:

I set up the array putting values in

wavfiles[6 ] = elemds.Tables[3].Rows[i ].ItemArray[3].ToString().Replace("\\", "\\\\");

and then on the radio button click i thought i could use

 private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
           
            SoundPlayer myPlayer = new System.Media.SoundPlayer();
              myPlayer.SoundLocation = @wavfiles[6 ];
              myPlayer.Play();
        }

I had also thought on creating a class to hold this array and store the values there but im not sure how to go about this.

If someone could help that would be much appricaiated.

Regards

Myles

推荐答案

Hello Myles,

Hello Myles,

我修改了您的代码,以使其如所描述的那样工作.

I adapted your code in order to make it work as described.

wavfiles[6 ] = elemds.Tables[3].Rows[i ].ItemArray[3].ToString().Replace("\\", "\\\\");
//you need a position-counter to remember the last file
private int pos=0;


private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (pos < wavsfiles.Length)
            {
                await Task.Delay(TimeSpan.FromSeconds(1));
                SoundPlayer myPlayer = new System.Media.SoundPlayer();
                myPlayer.SoundLocation = @wavfiles[pos++];
                myPlayer.Play();
            }            
        }

此致,
J·奥尔德普(J.Oldörp )   
MSDN Online德国开发人员热线

免责声明:
请考虑到,进一步的查询无法或将延迟答复.
有关更多信息,请通过MSDN-Entwickler-Hotline通过电话与我们联系: http://www.msdn-online.de/热线

对于MSDN-Entwickler-Hotline的帖子,以下 条款和条件 适用: 商标, 隐私权以及MSDN-Entwickler-Hotline的单独使用条款.

Regards,
J. Oldörp     
Developer-Hotline for MSDN Online Germany

Disclaimer:
Please take into consideration, that further inquiries cannot or will be answered with delay.
For further information please contact us per telephone through the MSDN-Entwickler-Hotline: http://www.msdn-online.de/Hotline

For this post by the MSDN-Entwickler-Hotline the following terms and conditions apply: Trademarks, Privacy as well as the separate terms of use for die MSDN-Entwickler-Hotline.


这篇关于从事件处理程序访问数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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