unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtDlgs, StdCtrls, ExtCtrls, Menus;type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    dlgOpenPic1: TOpenPictureDialog;
    pm1: TPopupMenu;
    N1: TMenuItem;
    SavePictureDialog1: TSavePictureDialog;
    procedure Button1Click(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure N1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    SourceRect,DescRect:TRect;
    draw:Boolean;
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
  if dlgOpenPic1.Execute then
     Image1.Picture.LoadFromFile(dlgOpenPic1.FileName);
end;procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if button=mbleft then
  begin
   image1.Canvas.DrawFocusRect(SourceRect);
   SourceRect.Left:=x;
   SourceRect.top:=y;
   SourceRect.right:=x;
   SourceRect.Bottom:=y;
   draw:=true;
  end;
end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if button=mbleft then
  begin
   SourceRect.right:=x;
   SourceRect.Bottom:=y;
   DescRect.top:=0;
   DescRect.Left:=0;
   DescRect.Right:=SourceRect.Right-SourceRect.Left;
   DescRect.Bottom:=SourceRect.Bottom-SourceRect.Top;
   //image2.Canvas.CopyRect(DescRect,image1.canvas,SourceRect) ;
   draw:=false;
  end;end;procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if draw then
begin
  image1.Canvas.DrawFocusRect(SourceRect);
  SourceRect.Right:=x;
  SourceRect.bottom:=y;
  image1.Canvas.DrawFocusRect(SourceRect);
end;end;procedure TForm1.N1Click(Sender: TObject);
var
  DescImg:TImage;
begin
  try
     DescImg := Timage.Create(application);
     DescImg.Height :=DescRect.Bottom;
     descImg.Width :=DescRect.Right;
     DescImg.Canvas.CopyRect(DescRect,image1.Canvas,SourceRect);
     if  SavePictureDialog1.Execute then
       descImg.Picture.SaveToFile(SavePictureDialog1.FileName+'.bmp');
  Finally
     freeandnil(descImg);
  end;
end;end.

解决方案 »

  1.   

    考虑用Frame吧
    具体去看Help
      

  2.   

    窗体注册后即可重用或继承右键菜单中Add to Repository
      

  3.   

    你上边的那段代码在我看来是不可能直接转换为控件的。。你可以考虑将你的窗体该为frame
      

  4.   

    大家可以误会我的意思了。
    我意思是:因为上面的事件都是围Image来操作的,所以想在image基础上做一个特殊的Image控件。
      

  5.   

    New->ComponentAncestor Type选择TImage取好新Class Name和待安装的面板,点Install选择安装的包在创建的新单元文件中,已经有了新类的声明,和注册函数在其中覆盖MouseDown,MouseMove,MouseUp即可
      

  6.   

    New->ComponentAncestor Type选择TImage取好新Class Name和待安装的面板,点Install选择安装的包在创建的新单元文件中,已经有了新类的声明,和注册函数在其中覆盖MouseDown,MouseMove,MouseUp即可
    严重同意