2个回答
展开全部
利用鼠标事件,控制他的位置就可以了
private void butPlan_MouseMove(object sender, MouseEventArgs e)
{
//播放歌曲快进
if (e.Button == MouseButtons.Left && butPlay.BackgroundImage == FFS)
{
timer2.Enabled = false;
butPlan.Location = new Point(MousePosition.X - this.Location.X-10, prTime.Location.Y);
if ( butPlan .Location.X < 2 )
{
butPlan.Location = new Point(prTime.Location.X, prTime.Location.Y);
}
if (butPlan.Location.X > prTime.Size.Width -4)
{
butPlan.Location = new Point(prTime.Location.X + prTime.Size.Width - 4, prTime.Location.Y);
}
prTime.Value = (MousePosition.X - this.Location.X-3) * (prTime.Maximum / prTime.Size.Width)-6000;
TT((prTime.Value/1000).ToString ());
}
}
private void butPlan_MouseCaptureChanged(object sender, EventArgs e)
{
try
{
timer2.Enabled = true;
Music.CurrentPosition = prTime.Value / 1000;
MusicLrc.Text = "";
}
catch { }
}
这是我做播放器是移动button控件的代码,你可以参考下
private void butPlan_MouseMove(object sender, MouseEventArgs e)
{
//播放歌曲快进
if (e.Button == MouseButtons.Left && butPlay.BackgroundImage == FFS)
{
timer2.Enabled = false;
butPlan.Location = new Point(MousePosition.X - this.Location.X-10, prTime.Location.Y);
if ( butPlan .Location.X < 2 )
{
butPlan.Location = new Point(prTime.Location.X, prTime.Location.Y);
}
if (butPlan.Location.X > prTime.Size.Width -4)
{
butPlan.Location = new Point(prTime.Location.X + prTime.Size.Width - 4, prTime.Location.Y);
}
prTime.Value = (MousePosition.X - this.Location.X-3) * (prTime.Maximum / prTime.Size.Width)-6000;
TT((prTime.Value/1000).ToString ());
}
}
private void butPlan_MouseCaptureChanged(object sender, EventArgs e)
{
try
{
timer2.Enabled = true;
Music.CurrentPosition = prTime.Value / 1000;
MusicLrc.Text = "";
}
catch { }
}
这是我做播放器是移动button控件的代码,你可以参考下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询