我使用开关进行alphabit增量和减量帮助我一切! [英] i using the switch for alphabit increment and decrement help me all some please!

查看:51
本文介绍了我使用开关进行alphabit增量和减量帮助我一切!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个代码来增加图像和alphabox在picturebox中的相同,因为我正在使用减量来编写casewitch--;哪个不能正常工作任何人都可以帮助我?

首次点击它增加然后它就会停在第一个alpahbit A和图像Apple(A for Apple)



------------------------------------------- -------------------------------------------------- -

i use this code for incremnt of the image and alphabit in picturebox same as i am using decrement in which i writing caseswitch--; that not working properly any one can help me?
on first click it increas and then it comes and stop on first alpahbit A and image Apple(A for Apple)

----------------------------------------------------------------------------------------------

private void button1_Click(object sender, EventArgs e)
{
   switch (caseswitch)
    {
        case 1:
            SoundPlayer player = new SoundPlayer(Properties.Resources.a);
            player.Play();
            pictureBox1.Image =(Properties.Resources.aa);
            pictureBox2.Image=(Properties.Resources.apple);
            caseswitch++;
            break;
        case 2:

            SoundPlayer playe = new SoundPlayer(Properties.Resources.b1);
            playe.Play();
            pictureBox1.Image = (Properties.Resources.bb);
            pictureBox2.Image=(Properties.Resources.ball);
            caseswitch++;
            break;
        case 3:
            SoundPlayer play = new SoundPlayer(Properties.Resources.c);
            play.Play();
            pictureBox1.Image = (Properties.Resources.cc);
            pictureBox2.Image=(Properties.Resources.cat);
            caseswitch++;
            break;
        case 4:
            SoundPlayer pla = new SoundPlayer(Properties.Resources.d);
            pla.Play();
            pictureBox1.Image = (Properties.Resources.dd);
            pictureBox2.Image=(Properties.Resources.dog);
            caseswitch++;
            break;
        case 5:
            SoundPlayer pl = new SoundPlayer(Properties.Resources.e);
            pl.Play();
            pictureBox1.Image = (Properties.Resources.ee);
            pictureBox2.Image=(Properties.Resources.elephant);
            caseswitch++;
            break;
        case 6:

            SoundPlayer p = new SoundPlayer(Properties.Resources.f);
            p.Play();
            pictureBox1.Image = (Properties.Resources.ff);
            pictureBox2.Image=(Properties.Resources.fish);
            caseswitch = 1;
            
            break;
    }
//----------------------------------------------------------------------------------------------
//                    DECREMNT IS 
//____________________________________________________________________________________________
private void button2_Click(object sender, EventArgs e)
{
   // string cse = "case1,case2,case3,case4,case5,case6";
    switch (caseswitch)
            
    {
        case 1:
            SoundPlayer player = new SoundPlayer(Properties.Resources.a);
            player.Play();
            pictureBox1.Image =(Properties.Resources.aa);
            pictureBox2.Image=(Properties.Resources.apple);
            
            break;
        case 2:

            SoundPlayer playe = new SoundPlayer(Properties.Resources.b1);
            playe.Play();
            pictureBox1.Image = (Properties.Resources.bb);
            pictureBox2.Image=(Properties.Resources.ball);
            caseswitch--;
            

            break;
        case 3:
            SoundPlayer play = new SoundPlayer(Properties.Resources.c);
            play.Play();
            pictureBox1.Image = (Properties.Resources.cc);
            pictureBox2.Image=(Properties.Resources.cat);
            caseswitch--;
            
            break;
        case 4:
            SoundPlayer pla = new SoundPlayer(Properties.Resources.d);
            pla.Play();
             pictureBox1.Image = (Properties.Resources.ee);
                pictureBox2.Image=(Properties.Resources.elephant);
            caseswitch--;
            break;
        case 5:
            SoundPlayer pl = new SoundPlayer(Properties.Resources.e);
            pl.Play();
             pictureBox1.Image = (Properties.Resources.ee);
             pictureBox2.Image=(Properties.Resources.elephant);
            caseswitch--;
            break;
        case 6:

            SoundPlayer p = new SoundPlayer(Properties.Resources.f);
            p.Play();
            pictureBox1.Image = (Properties.Resources.ff);
            pictureBox2.Image=(Properties.Resources.fish);
            caseswitch--;
            break;
            

    }
}

推荐答案

button2_Click ,您忘记了案例1中的 caseswitch - 语句。您还可以通过删除重复项来大大简化此代码来自每个案例的部分,甚至可能使用辅助方法来运行播放器并设置图像。



[edit]

我的错误,如果是1,你应该设置 caseswitch = 6



对于重复项,你可以设置一个列出所有资源元素,并按开关的索引值选择它们。

[/ edit]
In button2_Click, you forgot the caseswitch-- statement in case 1. You could also simplify this code considerably by removing the duplicate portions from each case, and possibly even using a helper method to run the player and set the image.

[edit]
My mistake, in case 1 you should set caseswitch = 6.

As to the duplicates, you could set up a list with all the resource elements, and select them by the index value of the switch.
[/edit]


这篇关于我使用开关进行alphabit增量和减量帮助我一切!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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