如何组合两个按钮

时间:2017-05-19 14:32:42

标签: c# winforms bass bass.dll

button_playbutton_pause。我想把它们组合成一个按钮。第一次按下歌曲时,歌曲开始播放。第二次按 - 暂停。在第三次按下时,播放继续。我做不到。

请告诉我,我如何将它们结合起来。

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();
}

2 个答案:

答案 0 :(得分:5)

类似的东西:

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;
}

答案 1 :(得分:0)

最简单的方法是创建一个新的Button对象,并添加正确的方法来显示正确的图像。像这样:

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;
    }
}

希望这有帮助!