winform开发时, 很多时候都需要创建非默认样式的窗体(因为很丑),而创建非默认样式的窗体又相当耗费时间。
为了节省时间,加快开发速度,这边将用过的一些代码,以及做自定义窗体过程中的一些思路整合了起来,做成一个工具类,其中包含设置边框,设置窗体的拖拽移动,设置最小化/关闭按钮等功能, 可以在一两分钟之内完成一个不错的自定义窗体。
下面是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Style
{
/// <summary>
///设定窗口边框(包括关闭及最小化),以及窗口移动。
/// </summary>
public class Border
{
#region 私有字段
/// <summary>
/// 边框对象现在操作的窗体
/// </summary>
Form form;
/// <summary>
/// 指示是否启用拖放
/// </summary>
private bool dragEnable = true;
/// <summary>
/// 用于关闭的label
/// </summary>
Label closeLabel = new Label();
/// <summary>
/// 用于最小化的lable
/// </summary>
Label miniLabel = new Label();
/// <summary>
/// 包含4个pictureBox边框的集合
/// </summary>
PictureBox[] picArray;
/// <summary>
/// 边框宽
/// </summary>
int borderWidth;
#endregion
#region 属性
/// <summary>
/// 指示是否启用拖放
/// </summary>
public bool DragEnable
{
get { return this.dragEnable; }
set { this.dragEnable = value; }
}
/// <summary>
/// 用于关闭的label
/// </summary>
public Label CloseLabel
{
get { return closeLabel; }
set { closeLabel = value; }
}
/// <summary>
/// 用于最小化的lable
/// </summary>
public Label MiniLabel
{
get { return miniLabel; }
set { miniLabel = value; }
}
/// <summary>
/// 边框宽
/// </summary>
public int BorderWidth