【问题标题】:How to replay the background music when I closed the new form关闭新表单时如何重放背景音乐
【发布时间】:2017-01-12 14:54:55
【问题描述】:

主窗体是form1,我在form1中有一个button1 单击按钮时,将显示 form2 我使用 axWindowsMediaPlayer1 播放背景音乐,单击 button1 后,音乐将停止并显示 form2。

private void button1_Click(object sender, EventArgs e)
{
    axWindowsMediaPlayer1.Ctlcontrols.stop();
    Form2 newForm2 = new Form2();
    newForm2.Show();
}

form2中还有一个按钮,点击form2会关闭。 现在我无法弄清楚如何在单击 form2 中的按钮后重放音乐。

【问题讨论】:

  • 你应该为你的表单和控件命名。
  • 问题不清楚,分享更多代码

标签: c# forms winforms wmp


【解决方案1】:

FormClosed 活动中开始您的音乐。它会在表单关闭时触发您的代码。

private void button1_Click(object sender, EventArgs e)
{
    axWindowsMediaPlayer1.Ctlcontrols.stop();
    Form2 newForm2 = new Form2();
    newForm2.FormClosed += (s, e) => axWindowsMediaPlayer1.Ctlcontrols.Start();
    newForm2.Show();
}

【讨论】:

  • 成功了,正是我想要的,非常感谢。
猜你喜欢
  • 2011-11-23
  • 2011-05-30
  • 2011-04-07
  • 2013-12-02
  • 2013-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多