FrmBoFang.cs
上传用户:fzwcsgshou
上传日期:2022-07-30
资源大小:28414k
文件大小:7k
源码类别:

行业应用

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace KTV
  9. {
  10.     public partial class FrmBoFang : Form
  11.     {
  12.         public FrmBoFang()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.         private bool tag = false;
  17.         public static DataSet ds = new DataSet();
  18.         private void FrmBoFang_Load(object sender, EventArgs e)
  19.         {
  20.             listBox1.DisplayMember = "歌曲名称";
  21.             listBox1.ValueMember = "存放位置";
  22.             ds.Tables.Add();
  23.             ds.Tables[0].Columns.Add("存放位置");
  24.             ds.Tables[0].Columns.Add("歌曲名称");
  25.             listBox1.DataSource = ds.Tables[0];   
  26.             
  27.         }
  28.         public int i = 0;
  29.         private int YouXianID = -1;
  30.         private void button9_Click(object sender, EventArgs e)
  31.         {
  32.             tag = false;
  33.             if (listBox1.Items.Count < 1)
  34.             {
  35.                 MessageBox.Show("请选择您要播放的歌曲!", "温馨提示", MessageBoxButtons.OK,
  36.                      MessageBoxIcon.Asterisk);
  37.                 return;
  38.             }
  39.             if (listBox1.SelectedValue.ToString() != "")
  40.             {
  41.                 axWindowsMediaPlayer1.URL = listBox1.SelectedValue.ToString();
  42.                 i = listBox1.SelectedIndex;
  43.                 
  44.             }
  45.             else
  46.             {
  47.                 MessageBox.Show("请选择您要播放的歌曲!", "温馨提示", MessageBoxButtons.OK,
  48.                      MessageBoxIcon.Asterisk);
  49.             }
  50.         }
  51.         private void btnBoFang_Click(object sender, EventArgs e)
  52.         {
  53.             if (listBox1.Items.Count < 1)
  54.             {
  55.                 MessageBox.Show("请选择您要播放的歌曲!", "温馨提示", MessageBoxButtons.OK,
  56.                      MessageBoxIcon.Asterisk);
  57.                 return;
  58.             }
  59.             axWindowsMediaPlayer1.Ctlcontrols.play();
  60.             tag = false;
  61.         }
  62.         private void btnZanTing_Click(object sender, EventArgs e)
  63.         {
  64.             axWindowsMediaPlayer1.Ctlcontrols.pause();
  65.         }
  66.         private void btnTingZhi_Click(object sender, EventArgs e)
  67.         {
  68.             axWindowsMediaPlayer1.Ctlcontrols.stop();
  69.             tag = true;
  70.         }
  71.         private void btnUp_Click(object sender, EventArgs e)
  72.         {
  73.             if (listBox1.Items.Count < 1)
  74.             {
  75.                 MessageBox.Show("请选择您要播放的歌曲!", "温馨提示", MessageBoxButtons.OK,
  76.                     MessageBoxIcon.Asterisk);
  77.                 return;
  78.             }
  79.             axWindowsMediaPlayer1.Ctlcontrols.previous();
  80.             listBox1.ClearSelected();
  81.             if (i == 0)
  82.             {
  83.                 i = listBox1.Items.Count - 1;
  84.             }
  85.             else
  86.             {
  87.                 i=i-1;
  88.             }
  89.             listBox1.SetSelected(i, true);
  90.             axWindowsMediaPlayer1.URL = ds.Tables[0].Rows[i]["存放位置"].ToString();
  91.         }
  92.         private void btnNext_Click(object sender, EventArgs e)
  93.         {
  94.             if (listBox1.Items.Count < 1)
  95.             {
  96.                 MessageBox.Show("请选择您要播放的歌曲!", "温馨提示", MessageBoxButtons.OK,
  97.                     MessageBoxIcon.Asterisk);
  98.                 return;
  99.             }
  100.             axWindowsMediaPlayer1.Ctlcontrols.next();
  101.             listBox1.ClearSelected();
  102.             if (i == listBox1.Items.Count - 1)
  103.             {
  104.                 i = 0;
  105.             }
  106.             else
  107.             {
  108.                 i = i + 1;
  109.             }
  110.             listBox1.SetSelected(i, true);
  111.             axWindowsMediaPlayer1.URL = ds.Tables[0].Rows[i]["存放位置"].ToString();
  112.         }
  113.         private void button8_Click(object sender, EventArgs e)
  114.         {
  115.             ds.Tables[0].Rows.RemoveAt(listBox1.SelectedIndex);
  116.         }
  117.         private void button10_Click(object sender, EventArgs e)
  118.         {
  119.             ds.Tables[0].Rows.InsertAt(ds.Tables[0].Rows[0],listBox1.SelectedIndex - 1);
  120.             
  121.             ds.Tables[0].Rows.RemoveAt(listBox1.SelectedIndex+1);
  122.         }
  123.         private void button7_Click(object sender, EventArgs e)
  124.         {
  125.             FrmXuanZe FrmXuanZe1 = new FrmXuanZe();
  126.             FrmXuanZe1.Show();
  127.         }
  128.         private void FrmBoFang_Shown(object sender, EventArgs e)
  129.         {
  130.             FrmXuanZe FrmXuanZe1 = new FrmXuanZe();
  131.             FrmXuanZe1.Show();
  132.         }
  133.         private void timer1_Tick(object sender, EventArgs e)
  134.         {
  135.             if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped && tag==false)
  136.             {
  137.                 if (YouXianID == -1)
  138.                 {
  139.                     listBox1.ClearSelected();
  140.                     if (comboBox1.Text.Trim() == "顺序播放")
  141.                     {
  142.                         if (i <= listBox1.Items.Count - 1)
  143.                         {
  144.                             i = -1;
  145.                         }
  146.                         i = i + 1;
  147.                     }
  148.                     else if (comboBox1.Text.Trim() == "倒叙播放")
  149.                     {
  150.                         if (i <=  0)
  151.                         {
  152.                             i = listBox1.Items.Count;
  153.                         }
  154.                         i = i - 1;
  155.                     }
  156.                     else if (comboBox1.Text.Trim() == "随机播放")
  157.                     {
  158.                         System.Random r = new Random();
  159.                         i=r.Next(listBox1.Items.Count);
  160.                     }
  161.                     listBox1.SetSelected(i, true);
  162.                     axWindowsMediaPlayer1.URL = ds.Tables[0].Rows[i]["存放位置"].ToString();
  163.                 }
  164.                 else
  165.                 {
  166.                     axWindowsMediaPlayer1.URL = ds.Tables[0].Rows[YouXianID]["存放位置"].ToString();
  167.                 }
  168.             }
  169.         }
  170.         private void btnQuanPing_Click(object sender, EventArgs e)
  171.         {
  172.             if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
  173.             {
  174.                 axWindowsMediaPlayer1.fullScreen = true;
  175.             }
  176.             else
  177.             {
  178.                 MessageBox.Show("请先播放,再点全屏!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  179.             }
  180.         }
  181.         private void btnYouXianBoFang_Click(object sender, EventArgs e)
  182.         {
  183.             YouXianID = listBox1.SelectedIndex;
  184.         }
  185.         private void pictureBox1_Click(object sender, EventArgs e)
  186.         {
  187.             MessageBox.Show("需要硬件设备支持!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  188.         }
  189.         private void button1_Click(object sender, EventArgs e)
  190.         {
  191.             if (MessageBox.Show("这里退出将关闭KTV点歌系统,您真的要退出吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  192.             {
  193.                 return;
  194.             }
  195.             Application.Exit();
  196.         }
  197.         private void FrmBoFang_FormClosing(object sender, FormClosingEventArgs e)
  198.         {
  199.             if (MessageBox.Show("这里退出将关闭KTV点歌系统,您真的要退出吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  200.             {
  201.                 return;
  202.             }
  203.             Application.Exit();
  204.         }
  205.     }
  206. }