一.自定义格式窗体
- 设置窗体无边框: this.FormBorderStyle = FormBorderStyle.None;
- 设置窗体大小: this.Size = new Size(500, 400);
- 设置窗体居中:this.Left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2;
this.Top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2; - 事件内部的代码严格按照从上到下顺序执行。
- 类,对象的抽象化,既对象。
- 实例化-创建一个新的对象。 Panel title = new Panel();
- 设置title的基本属性:
title.Width = this.Width;
title.Height = 30;
title.BackgroundImage = Image.FromFile("…/…/Image/Title.PNG");(插入背景图片) - 将title添加进Form1中:
this.Controls.Add(title); - 设置背景图片布局为拉伸:
title.BackgroundImageLayout = ImageLayout.Stretch; - 设置下半部分窗体的属性,背景
Panel border = new Panel(); Panel border = new Panel();
border.Width = this.Width;
border.Height = this.Height - title.Height;
border.BackgroundImage = Image.FromFile("…/…/Image/Border.PNG");
this.Controls.Add(border);
border.Top = title.Height;
border.BackgroundImageLayout = ImageLayout.Stretch; - 要求鼠标按下title时移动,窗体form1跟着变化,用布尔型变量标记鼠标按下时是true,前提是鼠标按下时。
bool isDown = false; - 事件中两个参数e、sender,e参数代表事件相对应的数据对象.
- if小括号中的条件语句结果是true或者false,里面填写bool类型数据
- 添加变量记录鼠标点击的Panle的坐标系中的位置
Point cilckPoint; - 获取鼠标的位置
Point currentPosition = MousePosition;
this.Location = new Point(currentPosition.X-cilckPoint.X,currentPosition.Y-cilckPoint.Y); - 要求当鼠标在拖着窗体移动的时候,可以隐藏
- bool isShow = false;(代表窗体目前的一个状态,如果是true代表处于显示状态,只有是false的时候才可以隐藏)
- timer1控制隐藏,timer2控制显示
- 通过if判断隐藏和显示条件,并且要求鼠标拖动到隐藏区域是离开窗体隐藏。
- MousePosition:获取鼠标光标的位置
- BackgroundImageLayout:获取或设置背景图的布局
- .BackgroundImage:设置背景图
- !既“非”
- 注意隐藏跟显示条件冲突