有些代码现在也不是很懂
1.拖动界面
//鼠标按住界面拖动
Point point1;//定义了一个点
private void Form1_MouseDown_1(object sender, MouseEventArgs e)
{
point1 = new Point(-e.X, -e.Y);
}
private void Form1_MouseMove_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point point2 = Control.MousePosition;
point2.Offset(point1.X, point1.Y);
Location = point2;
}
}
2.移动一个控件的位置
bool isMoveOut;//图片移动操作
private void pictureBox1_MouseEnter_1(object sender, EventArgs e)
{
//加号飞出来
timer1.Enabled = true;
isMoveOut = true;
}
private void pictureBox1_MouseLeave_1(object sender, EventArgs e)
{
//加号飞回来
timer1.Enabled = true;
isMoveOut = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
//加号随时间飞出去
if (isMoveOut)
{
picMultiUser.Location = new Point(picMultiUser.Location.X + 10, picMultiUser.Location.Y);
if (picMultiUser.Location.X >= 258)
{
timer1.Enabled = false;
}
}
//加号随时间移回来
if (!isMoveOut )
{
picMultiUser.Location = new Point(picMultiUser.Location.X - 10, picMultiUser.Location.Y);
if (picMultiUser.Location.X <= 190)
{
timer1.Enabled = false;
}
}
}