C# make borderless form moveable in windows application

make borderless form moveable For some reason you want to use the form border style None and user was not able to move the form with a mouse pick like other form border style, here is the snippet example shows how to move form boder style none to any location.
Capture the event mouse down x and y direction and place form location.

Download

Example Source Snippets - FormBorderStyleNone.zip

using System.Windows.Forms

How to move form boder style none to any location ?


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;

namespace FormBorderStyleNone
{
    public partial class Form1 : Form
    {      
        private Point mouseOffset;

        public Form1()
        {
            InitializeComponent();
        } 
        
        private void _MouseDown(object sender, MouseEventArgs e)
        {
            mouseOffset = new Point(-e.X, -e.Y);
        }

        private void _MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                this.Location = mousePos; //move the form to the desired location
            }
        }

        private void BtnMin_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void BtnMax_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Maximized)
                this.WindowState = FormWindowState.Normal;
            else
                this.WindowState = FormWindowState.Maximized;
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }     
    }
}


       

smartsnipps.ecomparefiles.com © 2019, All Rights Reserved | Disclaimer: smartsnipps.eCompareFiles.com is free to use any code snippets without guarantee