How to make a Window that does not have a Title bar move

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 05:28:48

问题


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.


回答1:


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.




回答2:


I wrote a component to do that, you can find it here.

It can be used to move any control, not just a window. You can either use it explicitly in code, or just drop it on the designer surface and set the EnableDragMove property on the window or control, as shown below :




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/1316744/how-to-make-a-window-that-does-not-have-a-title-bar-move

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!