第一步:首先引用DLL
再窗體中繼承DevComponents.DotNetBar.OfficeForm
public partial class MainForm : DevComponents.DotNetBar.OfficeForm初始化程序中添加 this.EnableGlass = false;
public MainForm() { this.EnableGlass = false; InitializeComponent(); }第二步:重繪標題欄
this.FormBorderStyle = FormBorderStyle.None;
先將原生窗體設置成無(wú)邊框,FormBoderStyle設置成None
然后添加一個(gè)panpel控件設置成窗體的的標題欄,并將panel的dock屬性設置為T(mén)op;
然后添加四個(gè)labell控件充當標題和最小化最大化關(guān)閉按鈕。
此時(shí)界面的原型就出來(lái)了。
第三步:最小最大關(guān)閉事件
注冊事件
this.panelEx1.MouseDown += panel1_MouseDown; this.MouseDown += MainForm_MouseDown;為事件添加處理方法
private void MinFormLabel_Click(object sender, EventArgs e) {
this.WindowState = FormWindowState.Minimized; }
private void MaxFormLabel_Click(object sender, EventArgs e) { if (this.WindowState != FormWindowState.Maximized) { this.WindowState = FormWindowState.Maximized; } else { this.WindowState = FormWindowState.Normal; } }
private void CloseFormLabel_Click(object sender, EventArgs e) { this.Close(); }第四步:窗體拖動(dòng)
[DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private const int VM_NCLBUTTONDOWN = 0XA1;//定義鼠標左鍵按下 private const int HTCAPTION = 2; private void MainForm_MouseDown(object sender, MouseEventArgs e) { //為當前應用程序釋放鼠標捕獲 ReleaseCapture(); //發(fā)送消息 讓系統誤以為在標題欄上按下鼠標 SendMessage((IntPtr)this.Handle, VM_NCLBUTTONDOWN, HTCAPTION, 0); } private void panel1_MouseDown(object sender, MouseEventArgs e) { //為當前應用程序釋放鼠標捕獲 ReleaseCapture(); //發(fā)送消息 讓系統誤以為在標題欄上按下鼠標 SendMessage((IntPtr)this.Handle, VM_NCLBUTTONDOWN, HTCAPTION, 0); }運行結果如下:
聯(lián)系客服