C#的窗体应用程序的窗口怎么让他编译后大小不可以改变?
1个回答
展开全部
可以通过隐藏窗体的边框来实现,同时为了让窗体能拖动位置,按以下操作:
设置窗体的属性 FormBorderStyle 为None,并给窗体添加如下事件(代码是网上找的,测试可行):
Point _Location;
Boolean _Down = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_Location = new Point(e.X, e.Y);
_Down = true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && _Down == true)
{
this.Left += e.X - _Location.X;
this.Top += e.Y - _Location.Y;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
_Down = false;
}
因隐藏边框后右上角关闭按钮也不可见,因此需要加入菜单退出按钮,以能够退出程序。
设置窗体的属性 FormBorderStyle 为None,并给窗体添加如下事件(代码是网上找的,测试可行):
Point _Location;
Boolean _Down = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_Location = new Point(e.X, e.Y);
_Down = true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && _Down == true)
{
this.Left += e.X - _Location.X;
this.Top += e.Y - _Location.Y;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
_Down = false;
}
因隐藏边框后右上角关闭按钮也不可见,因此需要加入菜单退出按钮,以能够退出程序。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询