Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
So i have been working on a program where you can call up wav files with buttons named tabs or by putting in the name of the note with a masked textbox. what i want is when i play my inputted note it collors my respective note in a line of arrays red. but when the note stops playin i want to have the original default color.

my code is like this:
playbutton:
C#
private void button1_Click(object sender, EventArgs e)
        {
            string noot;
            int i = 0,j = 0;
            noot = noottextbox.Text;
            Compare(noot, ref i, ref j);
            playtab(i,j);
            _tabs[i, j].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
        }

compare the input string with my array:
C#
private void Compare(string noot, ref int x, ref int y)
       {
           Boolean gevonden = false;
           x = 0;
           y = 0;
           for (int i = 0; i < 6 && !gevonden; i++)
               for (int j = 0; j < 13 && !gevonden; j++)
                   if (noot == _tabsnaam[i, j])
                   {
                       x = i;
                       y = j;
                       gevonden = true;
                   }
       }

play the note:
C#
private void playtab(int i, int j)
       {
           SoundPlayer tabsound = new SoundPlayer(@"C:\Users\Niko D'haes\Documents\Visual Studio 2005\Projects\guitarmidi\_FILES\beep.wav");
           if (i == 0 && j == 0)
           {
               tabsound.Play();
           }
       }

Now when i try to insert folowing line:
_tabs[i, j].UseVisualStyleBackColor = true;
in my buttonfunction, it just won't light up.
and when i put it behind my play function the button just stays red.
is there any way i can change the color back when it stops playin the sound?
Posted
Comments
E.F. Nijboer 9-Dec-10 6:51am    
Just as side note: In your method playtab, why do you create a SoundPlayer object with some chance that it isn't used? You could better move that line into the if statement and create the object only when needed.
niko D'haes 9-Dec-10 7:55am    
i'll keep that in mind, thank you

How about saving and restoring original color?

Regards
Espen Harlinn
 
Share this answer
 
Ok, so this won't answer your question, but why in the world did you write this:
C#
System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))))

First of all, why are you using all of those parentheses? You could just have easily written:
C#
System.Drawing.Color.FromArgb((int)(byte)255,(int)(byte)128,(int)(byte)255);

But to take it one step further, why in the world are you converting an integer value to a byte and then back into an int? The normal way to write than line would have just been:
C#
System.Drawing.Color.FromArgb(255,128,128);


As to your question...what Espen said...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900