我要求在一个已经显示在image里的图像(图像位于image的中央)上运用鼠标划定一个区域(可以是一个矩形),然后拖动这个区域,在这个图像上选择我所感兴趣的部分,再把最后确定的区域的四个顶点的坐标位置传送到一个过程里面
谢谢 那位大哥可以解答

解决方案 »

  1.   

    procedure ManipulateControl(Control: TControl;
      Shift: TShiftState; X, Y, Precision: integer);
    var
      SC_MANIPULATE: Word;
    begin
      //光标在控件的最左侧
      if (X <= Precision) and (Y > Precision) and (Y < Control.Height - Precision)
        then
      begin
        SC_MANIPULATE := $F001;
        Control.Cursor := crSizeWE;
      end
        //光标在控件的最右侧
      else if (X >= Control.Width - Precision) and (Y > Precision) and
        (Y < Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F002;
        Control.Cursor := crSizeWE;
      end
        //光标在控件的最上侧
      else if (X > Precision) and (X < Control.Width - Precision) and (Y <=
        Precision) then
      begin
        SC_MANIPULATE := $F003;
        Control.Cursor := crSizeNS;
      end
        //光标在控件的左上角
      else if (X <= Precision) and (Y <= Precision) then
      begin
        SC_MANIPULATE := $F004;
        Control.Cursor := crSizeNWSE;
      end
        //光标在控件的右上角
      else if (X >= Control.Width - Precision) and (Y <= Precision) then
      begin
        SC_MANIPULATE := $F005;
        Control.Cursor := crSizeNESW;
      end
        //光标在控件的最下侧
      else if (X > Precision) and (X < Control.Width - Precision) and
        (Y >= Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F006;
        Control.Cursor := crSizeNS;
      end
        //光标在控件的左下角
      else if (X <= Precision) and (Y >= Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F007;
        Control.Cursor := crSizeNESW;
      end
        //光标在控件的右下角
      else if (X >= Control.Width - Precision) and (Y >= Control.Height - Precision)
        then
      begin
        SC_MANIPULATE := $F008;
        Control.Cursor := crSizeNWSE;
      end
        //光标在控件的客户区(移动整个控件)
      else if (X > Precision) and (Y > Precision) and (X < Control.Width - Precision)
        and
        (Y < Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F009;
        Control.Cursor := crSizeAll;
      end
      else
      begin
        SC_MANIPULATE := $F000;
        Control.Cursor := crDefault;
      end;  if Shift = [ssLeft] then
      begin
        ReleaseCapture;
        Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
      end;
    end;procedure SampleMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      ManipulateControl(TControl(Sender), Shift, X, Y, 5);
      with TControl(Sender) do
      begin
        if Left < 0 then
          Left := 0;
        if Top < 0 then
          Top := 0;
        if Left + Width > Parent.Width then
          Left := Parent.Width - Width;
        if Top + Height > Parent.Height then
          Top := Parent.Height - Height;
        if Width < 20 then
          Width := 20;
        if Height < 20 then
          Height := 20;
      end;
    end;
    在Image的 MouseDown事件中AlarmRecBox:= TStaticText.Create(Self);//动态生成所画的框
      with AlarmRecBox do
      begin
        Left := x;
        Top := Y;
        Width := 50;
        Height := 50;
        Caption := '';
        Color := clFuchsia;
        Parent := stt_Window;
        BevelInner := bvLowered;
        BevelKind := bkTile;
        BevelOuter := bvRaised;
        Visible := True;
        OnMouseMove := SampleMouseMove;
      end;
      

  2.   

    怎么有这么多的错误[Error] kuang.pas(134): Undeclared identifier: 'AlarmRecBox'
    [Error] kuang.pas(134): Undeclared identifier: 'TStaticText'
    [Error] kuang.pas(134): Missing operator or semicolon
    [Error] kuang.pas(143): Undeclared identifier: 'stt_Window'
    [Error] kuang.pas(12): Unsatisfied forward or external declaration: 'TForm1.ManipulateControl'
    [Error] kuang.pas(13): Unsatisfied forward or external declaration: 'TForm1.SampleMouseMove'
      

  3.   

    引用StdCtrls单元
    uses
      StdCtrls;
    AlarmRecBox: TStaticText; stt_window:可以定义成TStaticText,哦,这里你是TImage;declaration: 'TForm1.ManipulateControl'
    [Error] kuang.pas(13): Unsatisfied forward or external declaration: 'TForm1.SampleMouseMove'
    你定义成窗体的函数即可嘛
      

  4.   

    这位大哥,怎么什么反应都没有?源程序:
    unit kuang;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls,StdCtrls;type
      TForm1 = class(TForm)
        Image1: TImage;
        AlarmRecBox: TStaticText;
        stt_window:TStaticText;
        //AlarmRecBox: TStaticText;
      procedure ManipulateControl(Control: TControl;Shift: TShiftState; X, Y, Precision: integer);
      procedure SampleMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
      procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    implementation{$R *.dfm}procedure TForm1.ManipulateControl(Control: TControl;
      Shift: TShiftState; X, Y, Precision: integer);
    var
      SC_MANIPULATE: Word;
    begin
      //光标在控件的最左侧
      if (X <= Precision) and (Y > Precision) and (Y < Control.Height - Precision)
        then
      begin
        SC_MANIPULATE := $F001;
        Control.Cursor := crSizeWE;
      end
        //光标在控件的最右侧
      else if (X >= Control.Width - Precision) and (Y > Precision) and
        (Y < Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F002;
        Control.Cursor := crSizeWE;
      end
        //光标在控件的最上侧
      else if (X > Precision) and (X < Control.Width - Precision) and (Y <=
        Precision) then
      begin
        SC_MANIPULATE := $F003;
        Control.Cursor := crSizeNS;
      end
        //光标在控件的左上角
      else if (X <= Precision) and (Y <= Precision) then
      begin
        SC_MANIPULATE := $F004;
        Control.Cursor := crSizeNWSE;
      end
        //光标在控件的右上角
      else if (X >= Control.Width - Precision) and (Y <= Precision) then
      begin
        SC_MANIPULATE := $F005;
        Control.Cursor := crSizeNESW;
      end
        //光标在控件的最下侧
      else if (X > Precision) and (X < Control.Width - Precision) and
        (Y >= Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F006;
        Control.Cursor := crSizeNS;
      end
        //光标在控件的左下角
      else if (X <= Precision) and (Y >= Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F007;
        Control.Cursor := crSizeNESW;
      end
        //光标在控件的右下角
      else if (X >= Control.Width - Precision) and (Y >= Control.Height - Precision)
        then
      begin
        SC_MANIPULATE := $F008;
        Control.Cursor := crSizeNWSE;
      end
        //光标在控件的客户区(移动整个控件)
      else if (X > Precision) and (Y > Precision) and (X < Control.Width - Precision)
        and
        (Y < Control.Height - Precision) then
      begin
        SC_MANIPULATE := $F009;
        Control.Cursor := crSizeAll;
      end
      else
      begin
        SC_MANIPULATE := $F000;
        Control.Cursor := crDefault;
      end;  if Shift = [ssLeft] then
      begin
        ReleaseCapture;
        Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
      end;
    end;procedure TForm1.SampleMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      ManipulateControl(TControl(Sender), Shift, X, Y, 5);
      with TControl(Sender) do
      begin
        if Left < 0 then
          Left := 0;
        if Top < 0 then
          Top := 0;
        if Left + Width > Parent.Width then
          Left := Parent.Width - Width;
        if Top + Height > Parent.Height then
          Top := Parent.Height - Height;
        if Width < 20 then
          Width := 20;
        if Height < 20 then
          Height := 20;
      end;
    end;
    procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      AlarmRecBox:= TStaticText.Create(Self);//动态生成所画的框
      with AlarmRecBox do
      begin
        Left := x;
        Top := Y;
        Width := 50;
        Height := 50;
        Caption := '';
        Color := clFuchsia;
        Parent := stt_Window;
        BevelInner := bvLowered;
        BevelKind := bkTile;
        BevelOuter := bvRaised;
        Visible := True;
        OnMouseMove := SampleMouseMove;
      end;
    end;end.
      

  5.   

    大虾 好像你的这个程序并不是我需要的意思?
    其实我这个有点像图像局部放大的意思 
    在一个原本的图像上选择一个局部让它经过一些处理在另外一个IMAGE里显示出来,只不过中间就有一个鼠标选择局部区域的问题:)
      

  6.   

    我的代码是可以用的,我都在用阿。
    AlarmRecBox。OnMouseMove := SampleMouseMove;AlarmRecBox。left
    AlarmRecBox.top
    AlarmRecBox.bottom
    四点坐标阿