[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Print screen - of selected component

Posted on 2006-05-28
10
Medium Priority
?
154 Views
Last Modified: 2011-04-14
Hi there,

Trying to do something really easy, but just can't do it!

I have a TShape component on my form with a TBevel around it. What I am trying to do is capture the screen but only show the TShape (basically, everything inside the TBevel.

basically

find screen location of TBevel
capture that part of the screen

Going mad :)
0
Comment
Question by:wildzero
  • 6
  • 4
10 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 1000 total points
ID: 16781121
I don't know how to do it with a TBevel persay, but if you put those things inside a control such as a TPanel, you can use the "PaintTo" method

uses printers;

begin
  if dlgPrint.Execute then
    begin
      with Printer do
      begin
        BeginDoc;
          Panel1.PaintTo(Handle, 10, 10);
        EndDoc;
      end;
    end;
end;
0
 
LVL 10

Author Comment

by:wildzero
ID: 16781184
Erm? dlgPrint?


I presume you mean

var
  bmp2 : TBitMap;
begin
  bmp2 := TBitMap.create;
  bmp2.Width := Panel1.Width;
  bmp2.Height := Panel1.Height;
  Panel1.PaintTo(bmp2.Canvas, 0, 0);
  bmp2.SaveToFile('C:\test2.bmp');
0
 
LVL 10

Author Comment

by:wildzero
ID: 16781191
Problem is lets say we devided that panel up into 4 equal segments
How could I get the top right 'piece' or the bottom right one using that method?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:wildzero
ID: 16781208
 bmp2 := TBitMap.create;
  bmp2.Width := Panel1.Width div 2;
  bmp2.Height := Panel1.Height div 2;
  Panel1.PaintTo(bmp2.Canvas, 0, 0);

that gets the top left corner


  bmp2.Width := Panel1.Width div 2;
  bmp2.Height := Panel1.Height div 2;
  Panel1.PaintTo(bmp2.Canvas, -(Panel1.Width div 2), 0);

gets the top right corner



  bmp2.Width := Panel1.Width div 2;
  bmp2.Height := Panel1.Height div 2;
  Panel1.PaintTo(bmp2.Canvas, 0, -(Panel1.Height div 2));

bottom left corner



  bmp2.Width := Panel1.Width div 2;
  bmp2.Height := Panel1.Height div 2;
  Panel1.PaintTo(bmp2.Canvas, -(Panel1.Width div 2), -(Panel1.Height div 2));

bottom right.

Phew!
0
 
LVL 10

Author Comment

by:wildzero
ID: 16781211
Any suggestions on that code? =)
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16781237
no,
by dlgprint, I mean a TPrintDialog (from the dialogs tab) placed on the form
the x and y properties of the "PaintTo" determine where to start printing the control on the printer page
0
 
LVL 10

Author Comment

by:wildzero
ID: 16781275
I thought it was odd to use a TPrintDialog when was trying to get the image into a bitmap
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16781703
hmm ok, your topic says "print screen" but if you just want to capture the area, what you want is something more like

var
    bmp: Tbitmap;
begin
    bmp := TBitmap.create;
    try
        bmp.width := panel1.width;
        bmp.height := panel1.height;
        Panel1.PaintTo(bmp.Canvas.Handle , 0, 0);
        image1.picture.assign(bmp); // just to prove that we got it.  
    finally
        bmp.free;
    end;
end;


don't know why you were doing the div 2 stuff
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16781728
if you want to do away with the "needing to be in a panel"
you can take a "screenshot" of the area you want like this :-
    var
        DC : HDC;
        bmp: tbitmap;
    begin
        bmp := tbitmap.create;
        try
            bmp.Width  := Bevel1.Width;
            bmp.Height := Bevel1.Height;
            BitBlt(bmp.canvas.handle, 0, 0, bmp.Width,
            bmp.Height,form1.Canvas.handle, Bevel1.Left, Bevel1.Top, SRCCOPY);
            image1.picture.assign(bmp); // show the captured area image
        finally
            bmp.free;
        end;
    end;

if your bevel is inside another control, you will need to change
...... form1.canvas.handle, Bevel1.Left, Bevel1.Top to...
...... form1.canvas.handle, Panel1.Left + Bevel1.Left, Panel1.Top + Bevel1.Top ...
0
 
LVL 10

Author Comment

by:wildzero
ID: 16781737
Ahh sorry my mistake :P Was wondering where you got the print bit from

Print Screen (Or PRT Screen) is the button to push when you do a screen shot which is what I ment (to take a screen shot).

I was able to use the first supplied code and modify it to suit my needs perfectly.

Thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question