Click here to Skip to main content
15,891,976 members
Articles / Mobile Apps
Article

Moving Form Without Titlebar

Rate me:
Please Sign up or sign in to vote.
3.00/5 (10 votes)
13 Jun 2007CPOL 26.9K   19   4
This code will help you in creating a customized form interface

Introduction

This will simply show you code that can customize the Graphical User Interface in your Windows application.

Background

I think you are familiar with the graphical user interface[GUI] of AVG Anti-Spyware Software... so what's new about that? Have you noticed that the GUI is like an edited photo? Have you noticed that it can move without dragging the title bar.

In this case, I will show you how we can actually do the same things.

Using the Code

Using this code will help you to customize your GUI:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form2 : Form
    {   public bool isMouseDown=false;
        public int xLast;
        public int yLast;
        
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                int newY = this.Top + (e.Y - yLast);
                int newX = this.Left + (e.X - xLast);

                this.Location = new Point(newX, newY);
            }
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;
            xLast = e.X;
            yLast = e.Y;
        }
    }
}
//

Points of Interest

In addition, did you know that you can make your own skins like in the WMP in this code?

You can do this as follows:

  • Get your edited photo <or your design Skins>
  • Place the photo in form application
  • Set Formborder to None
  • Set the Transparency of the form

THERE YOU HAVE IT... ENJOY!

History

  • 13th June, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Other
Philippines Philippines
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMoving Form like it should be Pin
ngoj25-Oct-07 2:13
ngoj25-Oct-07 2:13 
This is really awfully, you can't move form this way, it will flicker all around the screen.

We mast change approach and grab mouse down message in Window Procedure.
First we need to declare few constants (put this before form constructor):

const int WM_LBUTTONDOWN = 0x0201 ;
const int WM_NCLBUTTONDOWN = 0x00A1 ;
static readonly IntPtr HTCAPTION = new IntPtr ( 2 ) ;


Then we should redefine WndProc:

protected override void WndProc ( ref Message m )
{
try
{
if ( m.Msg == WM_LBUTTONDOWN )
{
m.Msg = WM_NCLBUTTONDOWN ;
m.WParam = HTCAPTION ;
}
}
catch {}
base.WndProc ( ref m ) ;
}

So every time we press left mouse button on form (not on controls)
Window will think we do it on form title bar and act accordingly ...

GeneralSmarter Solution Pin
christever22-Jun-07 19:28
christever22-Jun-07 19:28 
QuestionRe: Smarter Solution [modified] Pin
The_ERROR30-Jul-08 4:53
The_ERROR30-Jul-08 4:53 
GeneralNice, but here is a bunch of problems Pin
Marcos Meli13-Jun-07 6:03
Marcos Meli13-Jun-07 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.