[转万一] 不使用标题栏拖动窗体

http://www.cnblogs.com/del/archive/2008/04/30/1178226.html

方法一、二、三效果图:



方法四效果图:



方法一:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  f: Boolean;
  x1,y1: Integer;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  x1 := X;
  y1 := y;
  f := True;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if not f then Exit;
  Left := Left + X - x1;
  Top := Top + Y - y1;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  f := False;
end;

end.


方法二:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure MyMsg(var msg: TWMNCHitTest); message WM_NCHITTEST;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.MyMsg(var msg: TWMNCHitTest);
begin
  Inherited;
  if msg.Result = HTCLIENT then
    msg.Result := HTCAPTION;
end;

end.


方法三:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(Handle, WM_SYSCOMMAND, $F011, 0);
  {参数3在 $F011-$F01F 之间均可都是移动控件}
end;

end.


方法四:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(Handle, WM_SYSCOMMAND, $F011, 0);
end;

end.
时间: 2024-08-07 13:12:34

[转万一] 不使用标题栏拖动窗体的相关文章

非标题区域拖动窗体VB

窗体空白区域按下鼠标左键即可任意拖动窗体,不需要拖动标题栏. Dim MoveScreen As Boolean Dim MousX As Integer Dim MousY As Integer Dim CurrX As Integer Dim CurrY As Integer Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then

FormBorderStyle为None的时候如何拖动窗体

1 //为DllImport导出命名空间, 2 using System.Runtime.InteropServices; 3 public partial class Form1 : System.Windows.Forms.Form 4 { 5 #region FormBorderStyle为None,拖放窗体 6 [DllImport("user32.dll")] 7 public static extern bool ReleaseCapture(); 8 [DllImport

C#WinForm无边框窗体移动方法、模仿鼠标单击标题栏移动窗体位置

C#WinForm无边框窗体移动方法.模仿鼠标单击标题栏移动窗体位置 这里介绍俩种办法 方法一:直接通过修改窗体位置从而达到移动窗体的效果 方法二:直接伪装发送单击任务栏消息,让应用程序误以为单击任务栏从而移动窗体 新建窗体用于测试 方法一 1.定义一个位置信息Point用于存储鼠标位置 1 private Point mPoint; 2.给窗体等控件增加MouseDown和MouseMove事件 1 /// <summary> 2 /// 鼠标按下 3 /// </summary>

C#WinForm无边框窗体移动----模仿鼠标单击标题栏移动窗体位置

C#WinForm无边框窗体移动方法.模仿鼠标单击标题栏移动窗体位置 这里介绍俩种办法 方法一:直接通过修改窗体位置从而达到移动窗体的效果 方法二:直接伪装发送单击任务栏消息,让应用程序误以为单击任务栏从而移动窗体 新建窗体用于测试 方法一 1.定义一个位置信息Point用于存储鼠标位置 1 private Point mPoint; 2.给窗体等控件增加MouseDown和MouseMove事件 1 /// <summary> 2 /// 鼠标按下 3 /// </summary>

WPF无边框可拖动窗体

下面主要记录下创建无边框窗体,并且可以拖动.这种窗体主要用于弹出小窗体时. <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http

WPF中自定义标题栏时窗体最大化处理之WindowChrome

注意: 本文方法基础是WindowChrome,而WindowChrome在.NET Framework 4.5之后才集成发布的.见:WindowChrome Class 在.NET Framework 4.0中使用WindowChrome,需要安装Ribbon来支持WindowChrome 目前官方文档的内容较为陈旧(但仍有参考价值),其中提到了SystemParameters2,这个应该是Ribbon里的东西,4.5想用可以安装Xceed.Wpf.AvalonDock库,这里面有现成的Mic

WinForm 之 自定义标题栏的窗体移动

通过标题栏的鼠标事件实现窗体移动,代码如下: bool m_isMouseDown = false; //窗体是否移动 Point m_mousePos; //记录窗体的位置 /// <summary> /// 鼠标按下,开启移动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> priva

鼠标拖动窗体

1.鼠标在客户区拖动窗口 重载消息函数 procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest); begin inherited; //不可缺少 if (=Message.Result = HTCLIENT) then Message.Result := HTCAPTION; end; 2.鼠标在

Delphi 不用标题栏移动窗体

procedure TxxxxForm.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); const sc_DragMove: Integer = $F012; begin if ssCtrl in Shift then //判断"Ctrl"键是否按下 Begin ReleaseCapture; //释放鼠标事件的对象 //(Sender as TWinCon