Beranda > Delphi > How to get a screen shot of a control

How to get a screen shot of a control

Not only can you make screen shots of the whole screen but you can also save the image of controls too. The only catch is that the following functions is for controls that are descended from TWinControl. Most standard components in Delphi are. The following function takes an object as parameter and returns a bitmap containing it’s image. Have fun!

uses
  Graphics;
...
function Control2Bitmap(Control_: TWinControl): TBitmap;
begin
  Result := TBitmap.Create;
  with Result do begin
    Height := Control_.Height;
    Width  := Control_.Width;
    Canvas.Handle := CreateDC(nil, nil, nil, nil);
    Canvas.Lock;
    Control_.PaintTo(Canvas.Handle, 0, 0);
    Canvas.Unlock;
    DeleteDC(Canvas.Handle); 
  end;
end;
Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: