There is button_play and button_pause. I want to combine them into one button. The first time the song is pressed, the song starts playing. The second press - pause. At the third press, the playback continues. I can not do it.
Please tell me, how I can combine them.
private void button_play_Click(object sender, EventArgs e)
{
if ((list_catalog.Items.Count != 0) && (list_catalog.SelectedIndex != -1))
{
string current = Vars.Files[list_catalog.SelectedIndex];
Vars.CurrentTrackNumber = list_catalog.SelectedIndex;
BassLike.Play(current, BassLike.Volume);
label_time1.Text = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString();
label_time2.Text = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString();
xrewind.Maximum = BassLike.GetTimeOfStream(BassLike.Stream);
xrewind.Value = BassLike.GetPosOfStream(BassLike.Stream);
timer1.Enabled = true;
}
}
private void button_pause_Click(object sender, EventArgs e)
{
BassLike.Pause();
}
Something like:
private bool _isPlaying;
private void button_Click(object sender, EventArgs e)
{
if(!_isPlaying)
{
mediaThing.Play();
button1.Text = "Pause";
}
else
{
mediaThing.Pause();
button1.Text = "Play";
}
_isPlaying = !_isPlaying;
}
The easiest way is to create a new Button object, and add the proper method for displaying the correct image. Something like this:
public class ButtonStateHandler:MonoBehaviour {
public boolean isClicked;
public Button myBtn;
public Sprite Play;
public Sprite Pause;
public void Click(){
changeState();
}
private void changeState(){
isClicked = !isClicked;
if(isClicked) myBtn.image.sprite = Play;
else myBtn.image.sprite = Pause;
}
}
Hope this helps!
Related
I have a button that when clicked, changes its background image and opens another Form. I want that this background image changes again when I close the 2nd form (Cam) clicking on the X cross at the right corner. How can I do that? Should I use FormClosed() or FormClosing() events? Thank you.
private void CamBox1btn_Click(object sender, EventArgs e)
{
Camera Cam = new Camera();
if (bln)
{
CamBox1btn.Image = imageList1.Images[10];
Cam.ShowDialog();
}
else
{
CamBox1btn.Image = imageList1.Images[8];
}
bln = !bln;
}
Form 1:
private void CamBox1btn_Click(object sender, EventArgs e)
{
Camera Cam = new Camera();
if (Cam_bln)
{
CamBox1btn.BackgroundImage = Properties.Resources.Camera_button_ON;
Cam.eventForm += new ShowFrm(backgroundcolor_change_CAM);
Cam.ShowDialog();
}
else
{
CamBox1btn.BackgroundImage = Properties.Resources.Camera_button_OFF;
}
Cam_bln = !Cam_bln;
}
void backgroundcolor_change_CAM()
{
Cam_bln = false;
CamBox1btn.BackgroundImage = Properties.Resources.Camera_button_OFF;
}
Form2:
public delegate void ShowFrm();
public partial class Camera : Form
{
public event ShowFrm eventForm;
private void Camera_FormClosing(object sender, FormClosingEventArgs e)
{
eventForm?.Invoke();
}
}
So i have 2 forms, one is called "musica" and its playing a music (this form is invisible) and the other is called "Form1" and gives the option to stop and start the music with radio buttons.
The problem is that the radio buttons are working, but the video continues even if i click on "radionButton2" and if i use the "stop()" function on "musica_load" the music stops so i don't think the problem is from there either.
What is my mistake here?
Form1 code:
musica mus = new musica();
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
mus.play();
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
mus.stop();
}
}
musica code:
public void play()
{
axWindowsMediaPlayer1.Ctlcontrols.play();
}
public void stop()
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
}
// Form1.cs
musica mus;
public Form1()
{
InitializeComponent();
mus = new musica();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
mus.Play(); ;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
mus.Stop();
}
}
//Musica.cs
public musica()
{
InitializeComponent();
}
public void Play()
{
MessageBox.Show("Play");
}
public void Stop()
{
MessageBox.Show("Stop");
}
This works fine there must be some problem with the Play and Stop methods.
Answer: The problem was that i was opennig both forms simultaneously at the start of the program and for some reason they can't work between each other, if i open the musica.cs in Form1_load everything works!
Is there a way to create a method that goes like this in C#:
public void showHide(string shOne, string shTwo, string shThree) {
button1.shOne();
button2.shTwo();
button3.shThree();
}
private void discountButton_Click(object sender, EventArgs e) {
showHide("Show", "Hide", "Hide")
// I was thinking that this should be the same as
// button1.Show();
// button2.Hide();
// button3.Hide();
}
Is this possible ? I'm designing a c# application for thesis and I need to show and hide buttons (lots of buttons and labels and stuff).
I'm using this code as of now but I keep getting error:
Panel' does not contain a definition for 'shOne'.
public void showHide(bool shOne, bool shTwo, bool shThree)
{
button1.Visible = shOne;
button2.Visible = shTwo;
button3.Visible = shThree;
}
You can do this by multiple ways here is my code
private void button1_Click(object sender, EventArgs e)
{
if (button2.Visible == false)
{
button2.Show();
}
else
{
button2.Hide();
}
}
What the title says really, Right now I only know how to control the sound by using .Play and .Stop, however is there a way to mute the sound but still have it playing in the background?
Here is a snippet of the code:
private void muteButton_Click(object sender, EventArgs e)
{
if (muteButton.Text == "Mute")
{
muteButton.Text = "Unmute";
_soundPlayer.Stop();
}
else
{
muteButton.Text = "Mute";
_soundPlayer.PlayLooping();
}
}
You should try this
private boolean playing = true;
private void muteButton_Click(object sender, EventArgs e)
{
if (_soundPlayer.IsLoadCompleted)
{
if (playing)
{
_soundPlayer.Stop();
playing = false;
}
else
{
_soundPlayer.Play();
playing = true;
}
}
}
hi i have this code(and i get the ERROR that i must declare a body because it is not not marked abstract,extern or partial...by the way i couldnt get it to post it here but right over the public partial class Form1 : Form i also have written bool play1 = true;bool play2 = false; int x=1;int o=10; )when i click on it it goes up to that area that i marked with fat letters
could someone please show me what is wrong and how to solve it step by step
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
værdier();
int[] status = new int[9];
zeihne();
}
private string[] status;
private void value()
{
int[] status = new int[9];
zeihne();
}
private void zeihne()
{
button1.Text = status[0];
button2.Text = status[1];
button3.Text = status[2];
button4.Text = status[3];
button5.Text = status[4];
button6.Text = status[5];
button7.Text = status[6];
button8.Text = status[7];
button9.Text = status[8];
}
// private void label1_Click(object sender, EventArgs e)
{
}
**private void Form1_Load(object sender, EventArgs e);**
private void button1_Click(object sender, EventArgs e)
{
if (play1 == true)
{
play1 = true;
button1.Text = "X";
play1 = false;
}
else
{
play2 = true;
button1.Text = "O";
play2 = false;
play1 = true;
}
You haven't defined the method body for
private void Form1_Load(object sender, EventArgs e);
That's an abstract method and they are only allowed on abstract classes
Something like this would do the trick
private void Form1_Load(object sender, EventArgs e)
{
}
Or you can just get rid of the method if you don't plan to have any code on it.
EDIT
Something else that looks weird on your code is
// private void label1_Click(object sender, EventArgs e)
{
}
What are you trying to do? Two options:
// Option1: All the method commented
*/private void label1_Click(object sender, EventArgs e)
{
}*/
// Option2: Nothing commented
private void label1_Click(object sender, EventArgs e)
{
}
Hello Hwoarang H i tryed your code in my form and its working fine. You have to just follow step.
You have difine your method like this
private void Form1_Load(object sender, EventArgs e);
This is not right way to define method like this.You must declare like bellow
private void Form1_Load(object sender, EventArgs e)
{ }
Now remove your lable click event and brackets
// private void label1_Click(object sender, EventArgs e)
//{
//}
Now you got warning like x is issigned to but never used, o is assigned to but never used and status is assigned to but never used.No warry about that bcos you assign x and o as integer and used as string so this warning is come,i dont know whats your logic but if you want to remove this warning than use this int x,and o.Also play2 is never used so put condition like bellow
if (play1 == true)
{
btnSendNotification.Text = "x";
play1 = false;
}
else if(play2==true)
{
btnSendNotification.Text = "o";
play2 = false;
play1 = true;
}
Hope this is help you if not get solution than comment me.