首页 > 代码库 > C# 移动不规则窗体

C# 移动不规则窗体

说明: 解决自定义不规则窗体后,不能拖动问题。

先看效果图:

技术分享

技术分享

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;


namespace BT
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private Point mouse_offset;
        protected override void onm ouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            mouse_offset = new Point(-e.X, -e.Y);
        }

        protected override void onm ouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                Point mousepos = Control.MousePosition;
                mousepos.Offset(mouse_offset.X, mouse_offset.Y);
                Location = mousepos;
            }

        }
    }
}


C# 移动不规则窗体