天天看點

Winform GDI 系列(2) 窗體邊框重繪制

///<summary>
       ///窗體邊框重繪制
       ///</summary>
       ///<param name="sender"></param>
       ///<param name="e"></param>
       privatevoid Form1_Paint(object sender,PaintEventArgs e)
       {
            ///自定義繪制邊框顔色
            //e.Graphics.DrawRectangle(Pens.DarkOliveGreen,0, 0, this.Width - 1, this.Height - 1);
            e.Graphics.DrawRectangle(Common.FromCustomStyle.CustomFormBorder(),0, 0,this.Width -1, this.Height - 1);
        }      
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Common
{
    public static class FromCustomStyle
    {
        ///<summary>

        ///拖動Panel窗體移動

        ///</summary>

        ///<param name="form1">視窗執行個體</param>

        ///<param name="panel1">要拖動的Panel</param>

        ///<summary>

        ///拖動Panel窗體移動

        ///</summary>

        ///<param name="form1">視窗執行個體</param>

        ///<param name="panel1">要拖動的Panel</param>

        public static void MoveForm(Form form1, System.Windows.Forms.Panel panel1)

        {
            ReleaseCapture();
            SendMessage(form1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//*********************調用移動無窗體控件函數 
        }

        //定義無邊框窗體Form 

        [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;

    }
}