Move Windows Form Without Border

Introduction 


Some time its necessary that we want to move windows form without border. Especially when we making our form in abnormal shape rather then the normal rectangular shape. Hence we need to hide the Title bar of form and we can move the form from its Place. So here is the solution that how we can move that type of form.

Windows form will look like below:



Platform 

C# 2.0/3.5

Explanation of Implemented Logic

When we mouse click the form and hold it we will have 1 flag variable. We will make it true, then when we release the mouse click on form area we will set the flag to false; now when mouse moves then we will check if mouse click is hold or not by that flag variable. If the variable is true then make the form location same as Cursor location. That's it, so simple.

So lets see how to do it  by code

namespace MoveFormWithoutBoard

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        bool flag = false;

        private void Form1_MouseDown(object sender, MouseEventArgs e)

        { 

            flag = true;

        } 

        private void Form1_MouseMove(object sender, MouseEventArgs e)

        {

            //Check if Flag is True ??? if so then make form position same

            //as Cursor position

            if (flag == true)

            {

                this.Location = Cursor.Position; 

            }

        } 

        private void Form1_MouseUp(object sender, MouseEventArgs e)

        {

            flag = false;

        }

    }

}


Conclusion


This article explains the logic about how to move form without any border.


Similar Articles