如何通过窗体中的其他控件,实现对整个窗体的拖拽?请给出原码,谢谢。

解决方案 »

  1.   

    Too easy!Write down such code in MouseDown Event of your control:
      ReleaseCapture;
      SendMessage(Handle, WM_SYSCOMMAND, $F012, 0);
      

  2.   

    ReleaseCapture;
      SendMessage(Handle, WM_SYSCOMMAND, $F012, 0);
    或者继承WM_NCHITTEST消息
    或者perform guowzgyc(宝兰心情) 的消息
    或者自己写
    或者……
      

  3.   

    procedure WMNChitTest(var msg: TWMNCHITTEST); message WM_NCHITTEST;procedure Tform1.WMNChitTest(var Msg: TWMNCHITTEST);
    begin
      inherited;
      if (htClient=Msg.result) then Msg.result:=htCaption;
    end;
      

  4.   

    比如你的Form上有一个控件Panel!
    copy一段就可以了!!
    unit Unit1;
    ……
    type
    TForm1Κclass(TForm)
    procedureFormCreate(Sender:TObject);
    ……
    public
    {申明消息过滤过程}
    procedureAppMessage(varMsg:TMsg;varHandled:Boolean);
    ……
    implementation
    procedureTForm1.FormCreate(Sender:TObject);
    begin
    {捕捉消息:将程序的收到消息事件与消息过滤过程关联起来}
    Application.OnMessage:=AppMessage;
    end;
    procedureTForm1.AppMessage(varMsg:TMsg;varHandled:Boolean);
    begin
    {如果鼠标左键按下的话}
    if Msg.message=WM—LButtonDown then
    begin
    {判断光标是否在用户工作区内}
    if DefWindowProc(Panel1.Handle,WM—NCHitTest,0,GetMessagePos)=HTClient then
    begin
    {发出鼠标在用户标题栏内被按下的消息}
    SendMessage(Panel1.Handle,WM—NCLButtonDown,HTCaption,GetMessagePos);
    Handled:=true;
    {消息处理完毕,窗体不再接受MouseDown及Click事件,如果为false,程序的运行稍微有些不正常。}
    end;
    end;
    end;
    end.