···
Point downpoint;
Point movepoint;
bool ismoving;
//实现鼠标控制窗口移动
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
downpoint = e.Location;
ismoving = true;
}
private void timermove_Tick(object sender, EventArgs e)
{
}
//实现鼠标控制窗口移动(2)
private void mainForm_MouseMove(object sender, MouseEventArgs e)
{
if (ismoving == true)
{
movepoint = e.Location;
this.Location = new Point(
this.Location.X + (movepoint.X - downpoint.X),
this.Location.Y + (movepoint.Y - downpoint.Y)
);
}
}
//鼠标按键抬起窗口停止移动
private void mainForm_MouseUp(object sender, MouseEventArgs e)
{
ismoving = false;
}
····
···
bool isplaying = true;
string a;//歌曲总时间(字符串)
//点击播放:加载歌词
private void start_Click(object sender, EventArgs e)
{
if (tick == 0)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "mp3音乐|*.mp3|mp4音乐|*.mp4|flac文件|*.flac";//设置文件过滤,使之只能打开.mp3/.mp4/flac三种格式的音频文件
ofd.ShowDialog();
string fileName = ofd.FileName;
media.URL = fileName;
media.Ctlcontrols.play();
// start_Click(object sender, EventArgs e);
timer2.Enabled = true;
}
tick = 1;
timer1.Enabled = true;
Encoding encode = Encoding.GetEncoding("GB2312");
FileStream fs = new FileStream("陈一发儿-童话镇.lrc", FileMode.Open);
StreamReader sr = new StreamReader(fs, encode);
string s = sr.ReadLine();
//int xPos = 100;
int yPos = 50;
string a= media.currentMedia.durationString;
stime.Text = a;
while (s != null)
{
s = sr.ReadLine();
if(s==null)
{
break;
}
if (s.Equals(""))
{
continue;
}
Lyric1 lyric =new Lyric1();
lyric.minute =int.Parse(s.Substring(1,2));
lyric.second = int.Parse(s.Substring(4,2));
lyric.lyrics = s.Substring(10);
lyric.tosecond = lyric.minute * 60 + lyric.second;
//if(s.Substring(10)==null)
//{
// lyric.sminute = Convert.ToInt32(s.Substring(1, 1));
//lyric.ssecond = Convert.ToInt32(s.Substring(5, 1));
// }
listLyric1.Add(lyric);
yPos += 30;
}
if (isplaying)
{
start.BackgroundImage = Properties.Resources.play_circle_o;
isplaying = false;
media.Ctlcontrols.pause();
timer1.Enabled = false;
}
else
{
start.BackgroundImage = Properties.Resources.pause_circle_o;
isplaying = true;
media.Ctlcontrols.play();
timer1.Enabled = true;
}
fs.Close();
sr.Close();
}
···
···
Graphics g;//绘图对象
int PointY=140;
int current;
//主窗口绘制歌词
private void mainForm_Paint(object sender, PaintEventArgs e)
{
g = e.Graphics;
if (tick == 2)
{
for (int i = 0; i < listLyric.Count; i++)
{
if (i == current)
g.DrawString(listLyric[i].lyrics, new Font("微软雅黑", 17), Brushes.LightBlue, 400, PointY + i * 50);
else
g.DrawString(listLyric[i].lyrics, new Font("微软雅黑", 14), Brushes.White, 400, PointY + i * 50);
}
}
else
{
for (int i = 0; i < listLyric1.Count; i++)
{
if (i == current)
g.DrawString(listLyric1[i].lyrics, new Font("微软雅黑", 17), Brushes.LightBlue, 400, PointY + i * 50);
else
g.DrawString(listLyric1[i].lyrics, new Font("微软雅黑", 14), Brushes.White, 400, PointY + i * 50);
}
}
}
double position;
//时钟:不停调用刷新主窗口
private void timer1_Tick(object sender, EventArgs e)
{
//获取当前歌曲播放时间
position = media.Ctlcontrols.currentPosition;
int a = (int)position;
int m = a / 60;
int s = a % 60;
time1.Text = m.ToString();
time2.Text = s.ToString();
PointY-=1;
for (int i = 0; i < listLyric.Count-1; i++)
{
double b = listLyric[i].tosecond;
double c = listLyric[i+1].tosecond;
// int positioni = (int)position;
if (position > b && position < c)
current = i;
}
this.Invalidate(UpdateRect);
}
Rectangle UpdateRect;
//主窗口刷新
private void mainForm_Load(object sender, EventArgs e)
{
UpdateRect = new Rectangle(0, 0, this.ClientSize.Width,
this.ClientSize.Height - panel1.Height);
}
···
···
position = media.Ctlcontrols.currentPosition;
int a = (int)position;
int m = a / 60;
int s = a % 60;
time1.Text = m.ToString();
time2.Text = s.ToString();
string a = media.currentMedia.durationString;
stime.Text = a;
···
····
private void timer2_Tick(object sender, EventArgs e)
{
a = media.currentMedia.durationString;
int timm = int.Parse(a.Substring(1,1));
int tims = int.Parse(a.Substring(3,2));
int tim = timm * 60 + tims;
sizex += (610/ tim);
if(sizex<610&& isplaying==true)
{
going.Size = new Size(sizex, 10);
}
}
···
···
//Lyric1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kuwo
{
class Lyric1
{
public int minute;
public int second;
public int tosecond;
public string lyrics;
}
}
//Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace kuwo
{
public partial class mainForm : Form
{
List listLyric = new List();
List listLyric1 = new List();
int tick = 0;
public mainForm()
{
InitializeComponent();
}
Point downpoint;
Point movepoint;
bool ismoving;
//实现鼠标控制窗口移动(1)
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
downpoint = e.Location;
ismoving = true;
}
private void timermove_Tick(object sender, EventArgs e)
{
}
//实现鼠标控制窗口移动(2)
private void mainForm_MouseMove(object sender, MouseEventArgs e)
{
if (ismoving == true)
{
movepoint = e.Location;
this.Location = new Point(
this.Location.X + (movepoint.X - downpoint.X),
this.Location.Y + (movepoint.Y - downpoint.Y)
);
}
}
//鼠标按键抬起窗口停止移动
private void mainForm_MouseUp(object sender, MouseEventArgs e)
{
ismoving = false;
}
bool isplaying = true;
string a;//歌曲总时间(字符串)
//点击播放:加载歌词
private void start_Click(object sender, EventArgs e)
{
if (tick == 0)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "mp3音乐|*.mp3|mp4音乐|*.mp4|flac文件|*.flac";//设置文件过滤,使之只能打开.mp3/.mp4/flac三种格式的音频文件
ofd.ShowDialog();
string fileName = ofd.FileName;
media.URL = fileName;
media.Ctlcontrols.play();
// start_Click(object sender, EventArgs e);
timer2.Enabled = true;
}
tick = 1;
timer1.Enabled = true;
Encoding encode = Encoding.GetEncoding("GB2312");
FileStream fs = new FileStream("陈一发儿-童话镇.lrc", FileMode.Open);
StreamReader sr = new StreamReader(fs, encode);
string s = sr.ReadLine();
//int xPos = 100;
int yPos = 50;
string a= media.currentMedia.durationString;
stime.Text = a;
while (s != null)
{
s = sr.ReadLine();
if(s==null)
{
break;
}
if (s.Equals(""))
{
continue;
}
Lyric1 lyric =new Lyric1();
lyric.minute =int.Parse(s.Substring(1,2));
lyric.second = int.Parse(s.Substring(4,2));
lyric.lyrics = s.Substring(10);
lyric.tosecond = lyric.minute * 60 + lyric.second;
//if(s.Substring(10)==null)
//{
// lyric.sminute = Convert.ToInt32(s.Substring(1, 1));
//lyric.ssecond = Convert.ToInt32(s.Substring(5, 1));
// }
listLyric1.Add(lyric);
yPos += 30;
}
if (isplaying)
{
start.BackgroundImage = Properties.Resources.play_circle_o;
isplaying = false;
media.Ctlcontrols.pause();
timer1.Enabled = false;
//"C#openfiledialog 设置文件过滤"
}
else
{
start.BackgroundImage = Properties.Resources.pause_circle_o;
isplaying = true;
media.Ctlcontrols.play();
timer1.Enabled = true;
}
fs.Close();
sr.Close();
}
//打开本地资源
private void startplay_Click(object sender, EventArgs e)
{
tick = 2;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "mp3音乐|*.mp3|mp4音乐|*.mp4|flac文件|*.flac";//设置文件过滤,使之只能打开.mp3/.mp4/flac三种格式的音频文件
ofd.ShowDialog();
string fileName = ofd.FileName;
media.URL = fileName;
media.Ctlcontrols.play();
// start_Click(object sender, EventArgs e);
timer2.Enabled = true;
timer1.Enabled = true;
Encoding encode = Encoding.GetEncoding("GB2312");
FileStream fs = new FileStream("陈一发儿-童话镇.lrc", FileMode.Open);
StreamReader sr = new StreamReader(fs, encode);
string s = sr.ReadLine();
// int xPos = 100;
int yPos = 50;
string a = media.currentMedia.durationString;
stime.Text = a;
while (s != null)
{
s = sr.ReadLine();
if (s == null)
{
break;
}
if (s.Equals(""))
{
continue;
}
Lyric1 lyric = new Lyric1();
lyric.minute = int.Parse(s.Substring(1, 2));
lyric.second = int.Parse(s.Substring(4, 2));
lyric.lyrics = s.Substring(10);
lyric.tosecond = lyric.minute * 60 + lyric.second;
//if(s.Substring(10)==null)
//{
// lyric.sminute = Convert.ToInt32(s.Substring(1, 1));
//lyric.ssecond = Convert.ToInt32(s.Substring(5, 1));
// }
listLyric.Add(lyric);
yPos += 30;
}
fs.Close();
sr.Close();
}
//绘画
Graphics g;//绘图对象
int PointY=140;
int current;
//主窗口绘制歌词
private void mainForm_Paint(object sender, PaintEventArgs e)
{
g = e.Graphics;
if (tick == 2)
{
for (int i = 0; i < listLyric.Count; i++)
{
if (i == current)
g.DrawString(listLyric[i].lyrics, new Font("微软雅黑", 17), Brushes.LightBlue, 400, PointY + i * 50);
else
g.DrawString(listLyric[i].lyrics, new Font("微软雅黑", 14), Brushes.White, 400, PointY + i * 50);
}
}
else
{
for (int i = 0; i < listLyric1.Count; i++)
{
if (i == current)
g.DrawString(listLyric1[i].lyrics, new Font("微软雅黑", 17), Brushes.LightBlue, 400, PointY + i * 50);
else
g.DrawString(listLyric1[i].lyrics, new Font("微软雅黑", 14), Brushes.White, 400, PointY + i * 50);
}
}
}
double position;
//时钟:不停调用刷新主窗口
private void timer1_Tick(object sender, EventArgs e)
{
//获取当前歌曲播放时间
position = media.Ctlcontrols.currentPosition;
int a = (int)position;
int m = a / 60;
int s = a % 60;
time1.Text = m.ToString();
time2.Text = s.ToString();
PointY-=1;
for (int i = 0; i < listLyric.Count-1; i++)
{
double b = listLyric[i].tosecond;
double c = listLyric[i+1].tosecond;
// int positioni = (int)position;
if (position > b && position < c)
current = i;
}
this.Invalidate(UpdateRect);
}
Rectangle UpdateRect;
//主窗口刷新
private void mainForm_Load(object sender, EventArgs e)
{
UpdateRect = new Rectangle(0, 0, this.ClientSize.Width,
this.ClientSize.Height - panel1.Height);
}
int sizex = 42;
private void timer2_Tick(object sender, EventArgs e)
{
a = media.currentMedia.durationString;
int timm = int.Parse(a.Substring(1,1));
int tims = int.Parse(a.Substring(3,2));
int tim = timm * 60 + tims;
sizex += (610/ tim);
if(sizex<610&& isplaying==true)
{
going.Size = new Size(sizex, 10);
}
}
//点击播放
private void lyricstart_Click(object sender, EventArgs e)
{
// tick = 1;
if (timer1.Enabled == true)
timer1.Enabled = false;
else
timer1.Enabled = true;
}
}
}
···