C#winform中怎么实现无边框窗体的拖动、最大化、最小化以及关闭。
2013-04-24
展开全部
无边框窗体的移动:bool formMove = false;//窗体是否移动
Point formPoint;//记录窗体的位置 private void AddFriendForm2_MouseDown(object sender, MouseEventArgs e)
{
formPoint = new Point();
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
formPoint = new Point(xOffset, yOffset);
formMove = true;//开始移动
}
} private void AddFriendForm2_MouseMove(object sender, MouseEventArgs e)
{
if (formMove == true)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(formPoint.X, formPoint.Y);
Location = mousePos;
}
} private void AddFriendForm2_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
formMove = false;//停止移动
}
} 最大化最小化那些其实都是自己加的,可以用image点击事件里面实现最大化最小化以及关闭我用的是label: private void label1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
} private void label2_Click(object sender, EventArgs e)
{
this.Close();
}
Point formPoint;//记录窗体的位置 private void AddFriendForm2_MouseDown(object sender, MouseEventArgs e)
{
formPoint = new Point();
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
formPoint = new Point(xOffset, yOffset);
formMove = true;//开始移动
}
} private void AddFriendForm2_MouseMove(object sender, MouseEventArgs e)
{
if (formMove == true)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(formPoint.X, formPoint.Y);
Location = mousePos;
}
} private void AddFriendForm2_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
formMove = false;//停止移动
}
} 最大化最小化那些其实都是自己加的,可以用image点击事件里面实现最大化最小化以及关闭我用的是label: private void label1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
} private void label2_Click(object sender, EventArgs e)
{
this.Close();
}
2013-04-24
展开全部
画, mousedown mouseup mousemove down时标记拖动开始,记下鼠标位置,move时的鼠标位置,2个位置差改变localtion
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询