怎样可以使MID子窗体在主窗体中可以移动,但是又不会移动到主窗体客户区边界以外,即当MID子窗体移动到主窗体客户区边界以外后主窗体会出现滚动条,现在就是不想让主窗体出现滚动条.不知道我描述的问题大家是否遇到 如果有高手已经解决这个问题请告诉我,问题解决后立刻给分!谢谢

解决方案 »

  1.   

    用 SetWindowLong 將 對應主窗體的GWL_STYLE 中的 WS_HSCROLL,WS_VSCROLL 去掉!
      

  2.   

    不好意思我是DELPHI新手,刚学了几个月 aiirii(ari)前辈能说具体点吗? 应该在什么事件里写呢?谢谢啦
      

  3.   

    WS_HSCROLL,WS_VSCROLL
    的勾去掉就可以了
      

  4.   

    mxk19791116(幸运星)我的意思是说当鼠标拖动MID子窗体在主窗体的客户区中移动出客户区的边界时,主窗体会出现滚动条.能不能使MID子窗体只在主窗体的客户区中移动.Windows API我也没怎么用过 SetWindowLong 应该怎么用啊?还有aiirii(ari)前辈说的方法应该在窗体的什么事件里写代码呢?
      

  5.   

    移动MID子窗口时,判断在不在主窗口的客户区,超出就不能移动
      

  6.   

    laiguorong(Win Lai)这个办法我想过可是应该在什么事件中写代码呢,窗体的ONMOUSEMOVE事件是指移动窗体事件吗?应该怎么写?
      

  7.   


            SetWindowLong(Application.Handle,  GWL_STYLE,        GetWindowLong(Application.handle,  GWL_STYLE)        and not (WS_HSCROLL or WS_VSCROLL));
      

  8.   

    请问2312(theme_pengyi)是在哪里写这段代码?是不是MID子窗体创建的时候?
      

  9.   

    鼠标按住子窗体的移动消息是WM_NCHITTEST吗?还是有别的 不好意思 2312(theme_pengyi)可以具体点吗?不好意思我很菜!
      

  10.   

    我帮你写了一个,不知道符合你的要求不?
    unit Child1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Buttons, ExtCtrls;type
      TfrmChild1 = class(TForm)
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        procedure WMMOVE(var Message:TMessage);message WM_MOVE;
      public
        { Public declarations }
      end;var
      frmChild1: TfrmChild1;implementation{$R *.DFM}procedure TfrmChild1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action:=caFree;
    end;procedure TfrmChild1.FormCreate(Sender: TObject);
    begin
      frmChild1.DoubleBuffered:=true;
    end;procedure TfrmChild1.WMMOVE(var Message:TMessage);
    var Accept:boolean;
    begin
      if Message.Msg=WM_MOVE then
        begin
         if frmChild1.Left+frmChild1.Width>frmMain.Width then
           begin
           frmChild1.Left:=frmMain.Width-frmChild1.Width ;
           Accept:=true;
           end
         else if frmChild1.Left<0 then
           begin
           Accept:=true;
           frmChild1.Left:=0;
           end;
         if frmChild1.Top+frmChild1.Height>frmMain.Height then
           begin
           Accept:=true;       frmChild1.Top:=frmMain.Height-frmChild1.Height;
           end
         else if frmChild1.Top<0 then
           begin
           Accept:=true;
           frmChild1.Top:=0;
           end;
         if not Accept then
          inherited;
        end
     end;
    end.
      

  11.   

    谢谢2312(theme_pengyi)你的热心帮助 我按照你的这个代码试了下可是在创建MIDCHILD Form的时候报错了"Access violation at address 0044D972 in module 'project1.exe' read of address 00000040"然后错误行停留在消息处理过程中的"if frmChild1.Left+frmChild1.Width>frmMain.Width then"这句上.把消息处理过程注释掉也的话也会报错,错误行停留在"frmChild1.DoubleBuffered:=true;"这句上
    我创建MIDCHILD的代码是
      frmChild1:=tfrmChild1.Create(Application);
      frmChild1.Show;
    不知道是不是这里错了.
      

  12.   

    2312(theme_pengyi) 的方法应该是可以的。
      

  13.   

    是你创建MIDCHILD的问题,你应该换一种方式创建!
      

  14.   

    昨天试了一下,以下是我的方法FORM2是MIDCHILD FORM
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm2 = class(TForm)
      private
        { Private declarations }
        procedure FUpdateOnMOve(var Msg: TMsg); message WM_MOVE;//??????
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.dfm}procedure Tform2.FUpdateOnMOve(var Msg: TMsg);  //
    begin
      IF WINDOWSTATE<>wsMaximized THEN
      BEGIN
      IF Left<=0 THEN
        LEFT:=0;
      IF TOP<=0 THEN
        TOP:=0;
     IF (Left +WIDTH)>=APPLICATION.MainForm.ClientWidth-4 THEN
          Left:=APPLICATION.MainForm.ClientWidth-4-WIDTH;
      IF (TOP +HEIGHT)>=APPLICATION.MainForm.ClientHEIGHT-4 THEN
          TOP:=APPLICATION.MainForm.ClientHEIGHT-4-HEIGHT;
     END;
    end;end.
    这样可以解决最大化和正常情况下的移动问题,但是最小化后因为没有LEFT 和TOP 我不知道应该怎么去判断. 还有问下各位高手 TMESSAGE 和TMSG 这两个在使用消息的时候怎么区分,什么时候该用TMESSAGE 什么时候该用TMSG?
      

  15.   

    这种情况你就要判断了,我也想到了 TMESSAGE 和TMSG的问题,可能要两种结合使用!试试就知道了!