1. 程式人生 > >C#實現無邊框winfrom介面

C#實現無邊框winfrom介面

winfrom介面其實也可以扁平化,讓外觀提升一個level,整體為360風格。先上圖: 在這裡插入圖片描述

首先在介面屬性中,將FormBorderStyle設定為None,然後介面變為正常的Panel。此時需要新增頂欄拖動、最小化和關閉按鈕。


        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg,
int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; #region 窗體操作 /// <summary> /// 窗體拖動 /// </summary> private void panel1_MouseDown(object sender, MouseEventArgs e)
{ ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } /// <summary> /// 繪製邊框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private
void bodyPanel_Paint(object sender, PaintEventArgs e) { Pen p = new Pen(Color.FromArgb(109, 155, 241)); e.Graphics.DrawRectangle(p, 0, 0, this.bodyPanel.Width - 1, this.bodyPanel.Height - 1); } /// <summary> /// 最小化窗體 /// </summary> private void minPictureBox_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } /// <summary> /// 關閉窗體 /// </summary> private void closePictureBox_Click(object sender, EventArgs e) { Application.Exit(); } private void minPictureBox_MouseEnter(object sender, EventArgs e) { this.minPictureBox.Image = global::GSOperateMgrTool.Properties.Resources.最小化滑鼠經過; } private void minPictureBox_MouseLeave(object sender, EventArgs e) { this.minPictureBox.Image = global::GSOperateMgrTool.Properties.Resources.最小化; } private void closePictureBox_MouseEnter(object sender, EventArgs e) { this.closePictureBox.Image = global::GSOperateMgrTool.Properties.Resources.關閉滑鼠經過; } private void closePictureBox_MouseLeave(object sender, EventArgs e) { this.closePictureBox.Image = global::GSOperateMgrTool.Properties.Resources.關閉; } /// <summary> ///設定最小化和關閉圖片tip提示 /// </summary> private void SetToolTip() { //定義ToolTip物件 ToolTip toolTip = new ToolTip(); toolTip.AutoPopDelay = 5000; toolTip.InitialDelay = 100; toolTip.ReshowDelay = 500; toolTip.ShowAlways = true; toolTip.SetToolTip(this.minPictureBox,"最小化"); toolTip.SetToolTip(this.closePictureBox, "關閉"); }