Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting an image on a tab sheet

Status
Not open for further replies.

sggaunt

Programmer
Jul 4, 2001
8,620
GB
Rather than placing an image componenet on each tabsheet of a page control, it ought to be possible to draw onto the canvas, but a tabsheet dosnt seem to have a canvas property, I have a book that suggests that this can be done with a Tabcontrol, but this is not quite the same thing.
A page control does seem to have an ondrawtab event (in D4 at least) but my experiments with this produced nothing.
Does anyone know how to draw an image onto a Tabsheet of a Page control?

Steve.
 
Ive tried it in D5 with this:

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
PageControl1.Canvas.Draw(Rect.Left,Rect.Top,Image1.Picture.Graphic);
end;

which works,

Have you set the Ownerdraw porperty of the PageControl to True ?

Hth
- fruNNik
 
Thanks fruNNik
Good point about the Ownerdraw. The book based on D3 I think the ondrawtab event must only be present in later versions of Delphi.
So I will have to wait until I get back to My D4 machine.
Let you know if it works.

Steve
 
No go
I did get something after switching to owner draw.
but it seems to only put the image on the actual tab and a thin border around part of the edge of the tabsheet the actual (canvas?) area of the tabsheet remains grey.

Just the oppposite effect of dropping an image component on the tabsheet when you get a grey border.

As I mentioned the Delphi4 Page control component does have an ondrawtab event and I used the exact code that you posted. for the test I used a single pagecontrol with one page added, ownerdraw true.


 
Let me get this clear first ;)

Do you want to draw on the Tab or on the Page ?

I thought what you wanted was an icon beside the (regular) text on the tabs of the PageControl - is that right ?

- fruNNik
 
No I want to create a wizard using tabless tab pages and a nice background.
Steve
 
I decided to stop being lazy and converted the code in my book, I came up with this, that will draw any bitmap on the canvas of a windowed control. (provided the sender is cast correctly)

This is called by the onshow method of a Tabsheet and require a little jigging to make the first page display the background bitmap.

e.g
procedure tForm1.button1click(sender);
begin
//active page is 2
Pagecontrol1.activepage := two;
Pagecontrol1.visible := true;
//switch the active page to the first page forces a call
//to oneshow;
Pagecontrol1.activepage := one;
end;

procedure TForm1.oneshow(sender: tobject);
var canvas: Tcanvas;
R: tRect;
begin
R.left := 0;
R.top := 0;
R.right := (sender as TTabSheet).width;
R.Bottom := (sender as TTabSheet).height;
Canvas := tCanvas.create;
try
// creates a display handle for a widowed control
Canvas.handle := GetDC((sender as TTabsheet).handle);
try
with (sender as TTabsheet) do
begin
Canvas.stretchdraw(R, image.picture.graphic);
end;
finally
releaseDC((sender as TTabsheet).handle, canvas.Handle);
end;
finally
Canvas.free;
end;
end;

rather than using a static image as in the above example the final version loads the bitmap from a resource, and each sucessive tabsheet revealed does the same.

Then only problem is that there is still a thin grey border around the sheets.

Unless anyone can suggest any simplifications/corrected or borderless versions.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top