How to change backcolor of button in VS 2013 c++

Hello,

i have a little problem. How to change backcolor of button on red while sound is playing and change backcolor on normal when will be end of sound. Here is the piece of code:

1
2
3
4
5
6
7
8
  private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) 
{
    System::Media::SoundPlayer^ player = gcnew System::Media::SoundPlayer("g.wav");
    player->Load();
    player->PlaySync();
 
 
}
The media player component is a pure-Windows object.

You can change a button's color, but you should be aware that the Windows-ness of it means that you are playing with fire.

Best advice: you're wasting your time on this. Users will expect the control to behave normally.

If you must have this kind of control over the player UI, create your own player interface and simply defer actions to a hidden media player component.

Sorry.
thanks,

i want to do small game with piano simulator. Computer plays a few of notes and player has to repeat it. Maybe have you other solution for this problem, because player has to see which note was played (which button was clicked).
Um, now I'm confused. How exactly are you creating a piano if you aren't creating your own buttons?

Because surely you aren't using a media player component for each piano key?
I have 13 buttons and every button plays other sound. In my first post i pasted example of code for one button. I have one button which plays melody, this is code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private: System::Void button14_Click(System::Object^  sender, System::EventArgs^  e) {
		button5_Click(sender, e);
		button3_Click(sender, e);
		button3_Click(sender, e);
		button4_Click(sender, e);
		button2_Click(sender, e);
		button2_Click(sender, e);
		button1_Click(sender, e);
		button3_Click(sender, e);
		button5_Click(sender, e);
		button5_Click(sender, e);
		button3_Click(sender, e);
		button3_Click(sender, e);
		button4_Click(sender, e);
		button2_Click(sender, e);
		button2_Click(sender, e);
		button1_Click(sender, e);
		button3_Click(sender, e);
		button1_Click(sender, e);

	}


It works, but i only hear sounds but i don't see which button was clicked. This is my problem.
I'm not sure you understand my advice.

Update your button class to have a pressed and an unpressed color. (Personally, I would use images for the buttons... so there would be a pressed and unpressed image for the buttons.)

Then, to play your melody, you need to add a callback so that when the media player component terminates, it restores a button to its 'unpressed' state.

For each button to play, set it to 'pressed', invoke it's 'click' event, and wait.

Hope this helps.
Topic archived. No new replies allowed.