有人可以向我解释拖动无边界框架的简单程序吗? [英] can anyone explain me the simple program of dragging borderless frame ?

查看:83
本文介绍了有人可以向我解释拖动无边界框架的简单程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private const int HT_CAPTION = 0x2;   // what does this means
private const int WM_NCLBUTTONDOWN = 0x00A1;    // what does this means

[DllImport("user32", CharSet = CharSet.Auto)]
private static extern bool ReleaseCapture();       // what does this means

[DllImport("user32", CharSet = CharSet.Auto)]  // what does this means
private static extern int SendMessage(        // what does this means
    IntPtr hwnd,
    int wMsg,
    int wParam,
    int lParam);

protected override void OnMouseDown(MouseEventArgs e)// what does this means
{
    base.OnMouseDown(e);
    if (e.Button == MouseButtons.Left)
    {

                Rectangle rct = DisplayRectangle;
                if (
                    rct.Contains(e.Location))
                {
                    ReleaseCapture(); SendMessage(panel1.Parent.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
                }
            }
}     }

推荐答案

您需要阅读以下文章和讨论才能理解代码.
1. 在C#中移动不带标题栏的窗口/窗体 [ ^ ]
2. 制作无边界表单可移动对象 [创建任何形状的表单! [拖动不带标题栏的表单 [ ^ ]
5. C#移动不带边框/标题栏的表格 [ ^ ]
6.有关C语言的文章.您仍然可以参考概念. 创建可拖动窗口-SDI和对话框 [ HT_CAPTION: 表示鼠标操作发生在标题栏上.
2. WM_NCLBUTTONDOWN: 当在窗口的非客户区域上单击鼠标左键时,将向窗口发送WM_NCLBUTTONDOWN消息. WM_NCLBUTTONDOWN消息是那些消息之一. WM =窗口消息. NC =非客户,窗口不是客户区域,边框和标题栏的部分. L =左键,您可以找出BUTTONDOWN.
前缀0x在C语言中表示十六进制",就像& H在VB.NET中一样.
更多信息-
(WM_NCLBUTTONDOWN)有什么作用? [ DllImport("user32": 已添加,用于导入方法SendMessage()ReleaseCapture().
4. ReleaseCapture(): 从当前文档中的对象中删除鼠标捕获.通过鼠标告诉系统不再起作用.
5. SendMessage 将指定的消息发送到一个或多个窗口.它调用指定窗口的窗口过程,直到该窗口过程处理完该消息后才返回.
6. MouseDown: 此事件将包含在按下和拖动鼠标时执行表单移动操作的代码.
该技术背后的基本思想是使用Windows消息来处理表单移动.我们要做的就是每当用户按下鼠标按钮并移动鼠标时,我们都会发送一条消息,根据鼠标的移动来移动表单.
You need to go through the following articles and discussions to understand the code.
1. Move window/form without Titlebar in C#[^]
2. Making a Borderless Form Movable[^]
3. Create Forms in Any Shape![^]
4. dragging form without titlebar[^]
5. C# Moving form without border/title bar[^]
6. Article on C language. Still you can refer for concepts. Creating draggable windows - SDI and dialogs[^]

According to these articles I am briefing the concepts below...

1. HT_CAPTION: Indicates that the mouse action took place on the title bar.
2. WM_NCLBUTTONDOWN: The WM_NCLBUTTONDOWN message is sent to a window when a left mouse click is made on the non client area of the window. The WM_NCLBUTTONDOWN message is one of those messages. WM = Window Message. NC = Non Client, the part of the window that''s not the client area, the borders and the title bar. L = Left button, you can figure out BUTTONDOWN.
0x prefix means ''hexadecimal'' in the C language, just like &H does in VB.NET.
More info - What does ( WM_NCLBUTTONDOWN ) do?[^]
3. DllImport("user32": Added for importing methods SendMessage() and ReleaseCapture().
4. ReleaseCapture(): removes mouse capture from the object in the current document. Tell system through mouse didn''t working anymore.
5. SendMessage sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
6. MouseDown: This event will contain the code that will perform the form movement operation when the mouse is pressed and dragged.
The basic idea behind this technique is to use the windows messages to handle the form movement. What we will do is whenever the user press the mouse button and moves the mouse we will send a message to move the form according to the mouse movement.


这篇关于有人可以向我解释拖动无边界框架的简单程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆