Development/C#

C# WinForm 테두리 삭제 후 움직임 넣기

우봉수 2023. 2. 13. 17:22

C#의 기본 WinForm에서 맨위에 테두리 창이 디자인 적으로 예쁘지 않기 때문에 해당 부분을 없애고 따로 창을 움직일 수 있는 이벤트를 주고자 한다.

MouseDown 이벤트 더블클릭

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestWinForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        [DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
        private extern static void ReleaseCapture();

        [DllImport("user32.DLL", EntryPoint = "SendMessage")]
        private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int IParam);

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, 0x112, 0xf012, 0);
        }
    }
}

주의점: 창 내리기, 전체화면, 끄기 버튼은 따로 구현해야 한다.