- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
-
- namespace MusicPlayer
- {
- public partial class Form1 : Form
- {
- Bitmap originImg;
- Image finishImg;
- Graphics g;
- Point StartPoint, EndPoint;
- Pen p = new Pen(Color.Black, 2);
- bool IsDraw;
- bool IsPen;
- public Form1()
- {
- InitializeComponent();
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
- this.UpdateStyles();
- p.StartCap = LineCap.Round;
- p.EndCap = LineCap.Round;//将线帽样式设为圆线帽
- originImg = new Bitmap(picDraw.Width, picDraw.Height);
- g = Graphics.FromImage(originImg);
- g.Clear(Color.White); //画布背景初始化为白底
- picDraw.Image = originImg;
- finishImg = (Image)originImg.Clone();
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- DialogResult pathok;
- pathok = folderBrowserDialog1.ShowDialog(); //显示选择目录对话框
- if (pathok == DialogResult.OK) //如果单击OK 则获取目录内
- {
- string[] allfile = System.IO.Directory.GetFiles(folderBrowserDialog1.SelectedPath); //获取目录内所有文件
- foreach (string file in allfile)
- {
- if (System.IO.Path.GetExtension(file) == ".mp3" || System.IO.Path.GetExtension(file) == ".wma")
- {
- listBox1.Items.Add(System.IO.Path.GetFileName(file)); //在listBox1里显示文件
-
- }
- }
-
- }
- pause.Enabled = true;
- previous.Enabled = true;
- next.Enabled = true;
- delete.Enabled = true;
- trackBar1.Value = axWindowsMediaPlayer1.settings.volume;
- }
-
- private void listBox1_DoubleClick(object sender, EventArgs e)
- {
- axWindowsMediaPlayer1.URL = folderBrowserDialog1.SelectedPath + @"/" + listBox1.Items[listBox1.SelectedIndex].ToString();
- timer1.Enabled = true;
- }
-
- private void play_Click(object sender, EventArgs e)
- {
- axWindowsMediaPlayer1.Ctlcontrols.play();
- }
-
- private void pause_Click(object sender, EventArgs e)
- {
- axWindowsMediaPlayer1.Ctlcontrols.pause();
- play.Enabled = true;
- }
-
- private void previous_Click(object sender, EventArgs e)
- {
- --listBox1.SelectedIndex;
- axWindowsMediaPlayer1.URL = folderBrowserDialog1.SelectedPath + @"/" + listBox1.Items[listBox1.SelectedIndex].ToString();
- }
-
- private void next_Click(object sender, EventArgs e)
- {
- ++listBox1.SelectedIndex;
- axWindowsMediaPlayer1.URL = folderBrowserDialog1.SelectedPath + @"/" + listBox1.Items[listBox1.SelectedIndex].ToString();
- }
-
- private void delete_Click(object sender, EventArgs e)
- {
- if (listBox1.Text != null)
- { listBox1.Items.Remove(listBox1.Text); }
- ++listBox1.SelectedIndex;
- axWindowsMediaPlayer1.URL = folderBrowserDialog1.SelectedPath + @"/" + listBox1.Items[listBox1.SelectedIndex].ToString();
- }
-
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- axWindowsMediaPlayer1.settings.volume = trackBar1.Value;
- }
-
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (axWindowsMediaPlayer1.playState == (WMPLib.WMPPlayState)1)
- {
- ++listBox1.SelectedIndex;
- axWindowsMediaPlayer1.URL = folderBrowserDialog1.SelectedPath + @"/" + listBox1.Items[listBox1.SelectedIndex].ToString();
- }
-
- }
-
- private void mypen_Click(object sender, EventArgs e)
- {
- IsPen = true;
- }
-
- private void myeraser_Click(object sender, EventArgs e)
- {
- IsPen = false;
- }
-
- private void picDraw_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- IsDraw = true;
- StartPoint = e.Location;
- if (!IsPen)
- finishImg = (Image)originImg.Clone();
- }
- }
-
- private void picDraw_MouseMove(object sender, MouseEventArgs e)
- {
- if (IsDraw)
- {
- g = Graphics.FromImage(finishImg);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- EndPoint = e.Location;
- if (IsPen)
- {
- g.DrawLine(p, StartPoint, EndPoint);
- StartPoint = EndPoint;
- }
- else
- {
- Pen pen1 = new Pen(Color.White, 20);
- pen1.StartCap = LineCap.Round;
- pen1.EndCap = LineCap.Round;
- g.DrawLine(pen1, StartPoint, EndPoint);
- StartPoint = EndPoint;
- pen1.Dispose();
- }
- reDraw();
- }
- }
-
- private void picDraw_MouseUp(object sender, MouseEventArgs e)
- {
- IsDraw = false;
- originImg = (Bitmap)finishImg;
- picDraw.Image = originImg;
- }
- private void reDraw()
- {
- Graphics graphics = picDraw.CreateGraphics();
- graphics.DrawImage(finishImg, new Point(0, 0));
- graphics.Dispose();
- }
-
- private void savepic_Click(object sender, EventArgs e)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "jpg|*.jpg|png|*.png|bmp|*.bmp";
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- finishImg.Save(sfd.FileName);
- }
- }
-
- private void clearpic_Click(object sender, EventArgs e)
- {
- g.Clear(Color.White);
- reDraw();
- }
- }
- }
复制代码
|
|