无标题栏窗口的移动

代码
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.Runtime.InteropServices;

namespace 无标题栏窗口的移动
{
    
public partial class Form1 : Form
    {

        
const uint WM_SYSCOMMAND = 0x0112;
        
const uint SC_MOVE = 0xF010;
        
const uint HTCAPTION = 0x0002;

        [DllImport(
"user32.dll", EntryPoint = "SendMessageA")]
        
private static extern int SendMessage(IntPtr hwnd, uint wMsg, uint wParam, uint lParam);
        [DllImport(
"user32.dll")]
        
private static extern int ReleaseCapture();
        [DllImport(
"user32.dll")]
        
private static extern IntPtr SetCapture(IntPtr hwnd); 

        
public Form1()
        {
            InitializeComponent();
        }

        
private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage((sender 
as Control).Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);

        }

        
private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage((sender 
as Control).Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
    
        }

    }
}
原文地址:https://www.cnblogs.com/webcyz/p/1959728.html