设置窗体边框可以通过设置窗体的FormBorderStyle属性设置。属性值可以通过枚举类型FormBorderStyle获取,它的取值和意义如下表所示。
属 性 | 意 义 |
FormBorderStyle.None | 无边框 |
FormBorderStyle.FixedSingle | 固定的单行边框 |
FormBorderStyle.Fixed3D | 固定的三维样式边框 |
FormBorderStyle.FixedDialog | 固定的对话框样式的粗边框 |
FormBorderStyle.Sizable | 可调整大小的边框 |
FormBorderStyle.FixedToolWindow | 不可调整大小的工具窗口边框 |
FormBorderStyle.SizableToolWindow | 可调整大小的工具窗口边框 |
1.添加using using System.Runtime.InteropServices;
2. #region 本程序中用到的API函数
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwdn,int wMsg,int mParam,int lParam);//向指定的窗体发送Windows消息
#endregion
3.
#region 本程序中需要声明的变量
public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送的消息类型
public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息
public const int HTCAPTION = 0x0002;//该变量表示发送消息的附加消息
#endregion
4.ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//向Windows发送拖动窗体的消息
方法二:
//Point mouseOff;//鼠标移动位置变量
//bool leftFlag;//标签是否为左键
//private void 登陆窗口_MouseDown(object sender, MouseEventArgs e)
//{
// if (e.Button == MouseButtons.Left)
// {
// mouseOff = new Point(-e.X, -e.Y); //得到变量的值
// leftFlag = true; //点击左键按下时标注为true;
// }
//}
//private void 登陆窗口_MouseMove(object sender, MouseEventArgs e)
//{
// if (leftFlag)
// {
// Point mouseSet = Control.MousePosition;
// mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
// Location = mouseSet;
// }
//}
//private void 登陆窗口_MouseUp(object sender, MouseEventArgs e)
//{
// if (leftFlag)
// {
// leftFlag = false;//释放鼠标后标注为false;
// }
//}