tags:

views:

212

answers:

4

Is there any control that can move the Window without the Title bar(Top one)/No frame at all.

I am making a note application as you know so I want it to be compact.

+4  A: 

You need to return HTCAPTION from the WM_NCHITTEST in your WndProc:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    const int WM_NCHITTEST = 0x0084;
    const int HTCLIENT = 1;
    const int HTCAPTION = 2;
    protected override void WndProc(ref Message msg)
    {
        base.WndProc(ref msg);
        if (msg.Msg == WM_NCHITTEST && msg.Result == (IntPtr)HTCLIENT)
        {
            msg.Result = (IntPtr)HTCAPTION;
        }
    }
}

That will make the client area of your window seem to Windows to be a caption bar.

RichieHindle
Yes, this works but only if you (can) click on the Form's background. The term 'note application' makes me think of a window-filling textbox.
Henk Holterman
Where do I put this code?
Jonathan Shepherd
@Henk Holterman I do have "some" background :)You don't really need to move it, it will close itself in 15 second after inactivity. I just want to give user some freedom.
Jonathan Shepherd
@Jonathan: You put the code in your form - I've updated the example to show my complete test class.
RichieHindle
Got it working what ever. Thanks.
Jonathan Shepherd
It also work in the.partial class Main {part also. I decided to put it there it make the code cleaner :)
Jonathan Shepherd
@Jonathan: Cool. Note that I've just edited the code - the previous version broke the Close button (Red X) and family.
RichieHindle
Jonathan, it is usually not a good idea to put anything in the .Desgner.cs, you could lose it.
Henk Holterman
@Henk Holterman and I just lost it :) never mind I put it to the proper place now. Thanks.
Jonathan Shepherd
A: 

Having attempted something like this before I can tell you it isn't particularly easy. What you'll need to do is provided on an OnMouseDown/OnMouseMove/OnMouseUp event to the form itself (or some control in the form) that updates the position of the control when the user clicks and drags. To my knowledge there is no built in control that will allow you to click and drag a window other than the title.

Nathan Taylor
A: 

If you are going to build a application from scratch I would recommend creating it using WPF.

Todd Miranda has a great demonstration of creating a gadget like application over at windowsclient.net.

Link to the demonstration: http://windowsclient.net/learn/video.aspx?v=5177

+2  A: 
Thomas Levesque
This is a more complete answer thanks.
Jonathan Shepherd