.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Windows Application >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Move windows form without Border

Posted By:Kirtan       Posted Date: April 24, 2010    Points: 25    Category: Windows Application    URL: http://www.dotnetspark.com  

Some time its necessary that we want to move form without border. So here is the solution to move that type of form.
 

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.

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend