Search code examples
delphitabspreviewhints

Previews in delphi?


I am creating a project in Delphi and was wondering if it was is possible to create a preview of a tab. My idea is for a person to hover over the panel that takes you to the page and then it shows a preview in the hint, like when you hover over an icon in your task bar. if this is possible, would it also be possible to display the page instead of the panel as a preview and then click on it to go there? By this I mean almost like an image of the page, but my problem is that I don't want it to be a static screenshot of the page, I want it to be able to show the page as it is, with any changes made. The same applies to the hint(I.E Not a static image).

Any help, and explanations, would be greatly appreciated.


Solution

  • To get the current view of a TTabSheet, you should use a function much like this one:

    procedure TForm81.CopySheet(TAB: TTabSheet);
    var
      bmp   : TBitMap;
    
    begin
      bmp:=TBitMap.Create;
      try
        bmp.PixelFormat:=TPixelFormat.pf24bit;
        bmp.Width:=TAB.Width; bmp.Height:=TAB.Height;
        TAB.PaintTo(BMP.Canvas,0,0);
        // Do what you need to with the bmp, ie. show it in a hint, a preview window, etc.
      finally
        bmp.Free
      end
    end;
    

    The essential method is the "PaintTo" on the TAB (and most other TControls), which draws itself onto a TCanvas (f.ex. of a TBitmap, like above).

    I'll leave it up to you to fill out the "Do what you need to with the bmp, ie. show it in a hint, a preview window, etc." part :-)