Winform GDI 系列(2) 窗体边框重绘制

本文介绍了一种自定义窗体边框颜色的方法,并提供了一个实用的Panel拖动窗体的技术实现。通过使用.NET Framework的绘图功能,可以轻松地为窗体添加个性化的边框样式。此外,还展示了如何利用API函数实现拖动指定的Panel来移动整个窗体,这对于创建无边框窗口应用非常有用。

 

 

///<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);

        }

 

2.Panel移动可拖动窗体

 

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;

    }
}

 

04-26 142
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值