⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 C#程序开发范例宝典 图书光盘附带源码 第五章
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Ex05_03
{
    public partial class Form1 : Form
    {
        string strpath;
        public Form1()
        {
            InitializeComponent();
            strpath = System.Environment.CurrentDirectory;
        }
        static int i = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.FileName = "";
            this.openFileDialog1.ShowDialog();
            StreamWriter s = new StreamWriter(strpath + "\\HyList.ini", true);
            s.WriteLine(openFileDialog1.FileName);
            s.Flush();
            s.Close();
            ShowWindows(openFileDialog1.FileName); 
        }
        public void ShowWindows(string fileName)
        {
            this.listBox1.Items.Add(fileName);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            string str = Application.StartupPath;
            StreamReader sr = new StreamReader(str + "\\HyList.ini");
            while (sr.Peek() >= 0)
            {
                string strk=sr.ReadLine();
                if (strk!="")
                    listBox1.Items.Add(strk);    
            }
            sr.Close();
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            string strPath=listBox1.Items[listBox1.SelectedIndex].ToString();
            ShowPlay(strPath);
        }

        private void ShowPlay(string Path)
        {
            this.label2.Text = Path;
            this.axWindowsMediaPlayer1.URL =Path;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            i += 1;
            if (i % 2 == 0)
            {
                this.axWindowsMediaPlayer1.Ctlcontrols.play();
            }
            else
            {
                this.axWindowsMediaPlayer1.Ctlcontrols.pause();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ShowPlay(openFileDialog1.FileName);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.stop();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -