利用鼠标事件控制位置,比如:
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 { }
}
webform的话,楼上已经写好了,
winform的话:
button1.Location = new Point(0, 0);
button1.Style.Add("position", "absolute");
button1.Style.Add("left", "0");
button1.Style.Add("top", "0");
其它样式以此方法都可以添加