Advertisement
filhotecmail

TCircleImage

Sep 24th, 2020
1,663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.45 KB | None | 0 0
  1. type
  2.   TCircleImage = class(TCustomControl)
  3.     protected
  4.       procedure Paint; override;
  5.     public
  6.       constructor Create(AOwner: TComponent); override;
  7.   end;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Image1: TImage;
  12.     procedure CircleImageMouseDown(Sender: TObject; Button: TMouseButton;
  13.       Shift: TShiftState; X, Y: Integer);
  14.     procedure FormCreate(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.   CircleImage: TCircleImage;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. constructor TCircleImage.Create(AOwner: TComponent);
  30. begin
  31.   inherited Create(AOwner);
  32.   Width:= 100;
  33.   Height:= 100;
  34. end;
  35.  
  36. procedure TCircleImage.Paint;
  37. var aRect: TRect;
  38. begin
  39.   aRect:= Rect(0, 0, 100, 100);
  40.   Canvas.CopyRect(aRect, Form1.Image1.Canvas, aRect);
  41. end;
  42.  
  43. procedure TForm1.CircleImageMouseDown(Sender: TObject; Button: TMouseButton;
  44.   Shift: TShiftState; X, Y: Integer);
  45. var aHandle: THandle;
  46. begin
  47.   aHandle:= (Sender as TCircleImage).Handle;
  48.   BringWindowToTop(aHandle);
  49.   ReleaseCapture;
  50.   SendMessage(aHandle, WM_NCLBUTTONDOWN, 2, 0);    // 2 = HTCAPTION
  51. end;
  52.  
  53. procedure TForm1.FormCreate(Sender: TObject);
  54. begin
  55.   CircleImage:= TCircleImage.Create(Self);
  56.   CircleImage.Parent:= Self;
  57.   SetWindowRgn(CircleImage.Handle, CreateEllipticRgn(0, 0, 100, 100), true);
  58.   CircleImage.OnMouseDown:= CircleImageMouseDown;
  59.   CircleImage.Left:= 10;
  60.   CircleImage.Top:= 10;
  61. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement