哪位大哥能教教小弟如何制作自制的可以拖动的组件???急!!!万分感谢!!!

解决方案 »

  1.   

    有控件的onmousemove中调用此函数,即可实现该控件在运行时任意拖动和改变大小,procedure ManipulateControl(WinControl: TControl; Shift: TShiftState;X, Y, ecision: integer);
    var
      SC_MANIPULATE: Word;
    begin
      //光标在控件的最左侧
      if (X<=Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then
      begin
        SC_MANIPULATE  := $F001;
        WinControl.Cursor := crSizeWE;
      end
      else
        //光标在控件的最右侧
        if (X>=WinControl.Width-Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then
        begin
          SC_MANIPULATE  := $F002;
          WinControl.Cursor := crSizeWE;
        end
        else
          //光标在控件的最上侧
          if (X>Precision) and (X<WinControl.Width-Precision) and (Y<=Precision) then
          begin
            SC_MANIPULATE  := $F003;
            WinControl.Cursor := crSizeNS;
          end
          else
            //光标在控件的最下侧
            if (X>Precision) and (X<WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
            begin
              SC_MANIPULATE  := $F006;
              WinControl.Cursor := crSizeNS;
            end
            else
              //光标在控件的左上角
              if (X<=Precision) and (Y<=Precision) then
              begin
                SC_MANIPULATE  := $F004;
                WinControl.Cursor := crSizeNWSE;
              end
              else
                //光标在控件的右上角
                if (X>=WinControl.Width-Precision) and (Y<=Precision) then
                begin
                  SC_MANIPULATE  := $F005;
                  WinControl.Cursor := crSizeNESW ;
                end
                else
                  //光标在控件的左下角
                  if (X<=Precision) and (Y>=WinControl.Height-Precision) then
                  begin
                    SC_MANIPULATE  := $F007;
                    WinControl.Cursor := crSizeNESW;
                  end
                  else
                    //光标在控件的右下角
                    if (X>=WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
                    begin
                      SC_MANIPULATE  := $F008;
                      WinControl.Cursor := crSizeNWSE;
                    end
                    else
                      //光标在控件的客户区(移动整个控件)
                      if (X>5) and (Y>5) and (X<WinControl.Width-5) and
                            (Y<WinControl.Height-5) then
                      begin
                        SC_MANIPULATE  := $F009;
                        WinControl.Cursor := crSizeAll;
                      end
                      else
                      begin
                        SC_MANIPULATE := $F000;
                        WinControl.Cursor := crDefault;
                      end;
      if Shift=[ssLeft] then
      begin
        ReleaseCapture;
        WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
      end;
    end;
      

  2.   

    能将引用的文件给我看看吗
    我不太明白Precision什么意思
    谢谢了!!!
      

  3.   

    Precision:表示精度!
    procedure TLine.MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
    begin
      ManipulateControl(TLine(Sender),Shift,X,Y,2); //这是我自已在控件里引用的
    end;
      

  4.   

    cherrylin(伊雪)大哥:
    能不能把你这一部分的完整程序还有演示程序给我看看???
    我是个菜鸟,完整些看得明白,多谢了
      

  5.   

    Precision是表示某一个具体的值还是什么???
    谢谢了!!!
      

  6.   

    楼主,首先申明我不是男的,你搞错了,名字听起来像男的吗?
    我完整的就在上面了,你编译不过去,不会吧!
    出现什么错误?1.先在Public中申明该过程:
    procedure ManipulateControl(WinControl: TControl; Shift: TShiftState;X, Y, ecision: integer);
    2.写这个过程,就是上面粘贴的:
    procedure TForm1.ManipulateControl(WinControl: TControl; Shift: TShiftState;X, Y, ecision: integer);  (TForm1是窗体的名称)
    begin
      .....
    end;
    3.然后在你所要拖拉的控件的onmousemove引用该过程:
    procedure TForm1.MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
    begin
      ManipulateControl(Button1,Shift,X,Y,2); //这里面2就表示精度!
    end;再试试吧!
      

  7.   

    更正一下第3点:
    procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      ManipulateControl(Button1,Shift,X,Y,2); 
    end;
      

  8.   

    非常对不起 cherrylin(伊雪)大姐:
    只能这样称呼了,你不介意吧,没别的意思,只是出于尊敬!!!
    我想能不能像别的事件一样通过声明类似于ondblclick事件声明ondragdrop然后在其中加入需要的东西完成自制拖动事件的添加???
      

  9.   

    cherrylin(伊雪)大姐:
    你这个不是自制的组件吧???
    能安装吗???
      

  10.   

    这只是一个过程啊,如果你想做在控件里面也可以啊,以下是我自已用在控件中的,参考一下吧!unit Line;interfaceuses
      Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,Graphics,Menus,StdCtrls,Dialogs,Forms,
      Buttons;type
      TLine = class(TPanel)
      private
        { Private declarations }
      protected
        { Protected declarations }
        procedure MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
      public
        { Public declarations }
        constructor Create(Aowner:TComponent);override;
        destructor destroy;override;
      published
        { Published declarations }
        property Height default 5;
        property Width default 100;
        property Color default clBlack;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Standard', [TLine]);
    end;{TLine}procedure ManipulateControl(WinControl: TControl; Shift: TShiftState;X, Y, Precision: integer);
                                    //Precision:精度,该方法可以在onmousemove中调用
    var
      SC_MANIPULATE: Word;
    begin
      //光标在控件的最左侧
      if (X<=Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then
      begin
        SC_MANIPULATE  := $F001;
        WinControl.Cursor := crSizeWE;
      end
      else
        //光标在控件的最右侧
        if (X>=WinControl.Width-Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then
        begin
          SC_MANIPULATE  := $F002;
          WinControl.Cursor := crSizeWE;
        end
        else
          //光标在控件的最上侧
          if (X>Precision) and (X<WinControl.Width-Precision) and (Y<=Precision) then
          begin
            SC_MANIPULATE  := $F003;
            WinControl.Cursor := crSizeNS;
          end
          else
            //光标在控件的最下侧
            if (X>Precision) and (X<WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
            begin
              SC_MANIPULATE  := $F006;
              WinControl.Cursor := crSizeNS;
            end
            else
              //光标在控件的左上角
              if (X<=Precision) and (Y<=Precision) then
              begin
                SC_MANIPULATE  := $F004;
                WinControl.Cursor := crSizeNWSE;
              end
              else
                //光标在控件的右上角
                if (X>=WinControl.Width-Precision) and (Y<=Precision) then
                begin
                  SC_MANIPULATE  := $F005;
                  WinControl.Cursor := crSizeNESW ;
                end
                else
                  //光标在控件的左下角
                  if (X<=Precision) and (Y>=WinControl.Height-Precision) then
                  begin
                    SC_MANIPULATE  := $F007;
                    WinControl.Cursor := crSizeNESW;
                  end
                  else
                    //光标在控件的右下角
                    if (X>=WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
                    begin
                      SC_MANIPULATE  := $F008;
                      WinControl.Cursor := crSizeNWSE;
                    end
                    else
                      //光标在控件的客户区(移动整个控件)
                      if (X>5) and (Y>5) and (X<WinControl.Width-5) and
                            (Y<WinControl.Height-5) then
                      begin
                        SC_MANIPULATE  := $F009;
                        WinControl.Cursor := crSizeAll;
                      end
                      else
                      begin
                        SC_MANIPULATE := $F000;
                        WinControl.Cursor := crDefault;
                      end;
      if Shift=[ssLeft] then
      begin
        ReleaseCapture;
        WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
      end;
    end;constructor TLine.Create(Aowner:TComponent);
    begin
      inherited Create(AOwner);
      Height :=20;
      Width :=200;
      Color :=clBlack;  OnMouseMove :=MouseMove;
      end;
    end;destructor TLine.destroy;
    begin
      inherited;
    end;procedure TLine.MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
    begin
      ManipulateControl(TLine(Sender),Shift,X,Y,2)
    end;end.
      

  11.   

    cherrylin(伊雪)大姐:
    我刚学习delphi三个月,能不能把你的联系方式给我?我以后有问题可以向你请教!!!
    我的qq:57490953邮箱:[email protected]