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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

About TabSheets.

Status
Not open for further replies.

zikar

Programmer
Oct 10, 2000
31
JP
Hi,

How can I draw to a sheet (TTabSheet) in a TPageControl.

I have tried to fool around with FormPaint and Canvaslike in a standard form, since I know this works.

But it does not seem to be the way to go in the case of TPageControl.

Any sample or useful tip will be appreciated.

Thanks.

Michel
 
Thanks for the tip, but is there a sample code somewhere on how to use TPanel in that case ?
All samples I found are fairly complicated and doing more than what I need. I just would like to be able to draw some thing in my tabsheet for a start.

I have to deckare TPanel *p; and then appearently to do a p=new TPanel(???); and then what ?
Do I need a delete TPanel; some where ?

If I just knew : say how to draw a line ( or a square), that would be enough.

Michel
 
I apologize for the error above. I was going for
property of canvas in the TPanel. You may look into the TCanvas.
TForm has a canvas property.

Form1->Canvas.

used here.

void __fastcallTForm1::FormPaint(TObject *Sender)

{
Canvas->Rectangle(0, 0, ClientWidth/2, ClientHeight/2);
Canvas->Ellipse(0, 0, ClientWidth/2, ClientHeight/2);
}

The following code draws a line from the upper left corner of a form to the mouse position when the mouse is moved, creating a “rubber band” effect.

void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)

{
/* first call FillRect to paint the surface of the form.
this removes any previously drawn lines (and anything else!) */
Canvas->FillRect(ClientRect);
Canvas->MoveTo(0, 0);
Canvas->LineTo(X, Y);
}

Precisely if your object has a canvas property you can paint to it. There may be some examples in the examples folder.

Strangely the Tpagecontrol has a canvas property while TTabsheet does not.


tomcruz.net
 
Thanks,

By looking at your tip plus a few other things I found on the net. And also by trial and errors, it finally works.

I put the drawing code in the TPageControl "change" event handler, and I fire a Repaint() in the TTabSheet "show" event handler. I don't know if this is how it is supposed to be done but it works.

Michel
 
There are two approaches. One is to override the PaintHandler(Messages::TWMPaint &Message) event. This requires you to know a little more about working with DC's. It also doesn't provide you with the simple object oriented approach that the TCanvas does, thereby allowing you to draw rectangles, squares, etc, easily.

Since you are working with a TTabSheet, it is not an easy task. The hierarchy of TTabSheet includes at it's highest the TWinControl class. This class does not have a Canvas to paint to. Perhaps the developers would have been better to derive the TTabSheet from TCustomControl, which has a Canvas. You can do this though. You would need to change the existing source code for TTabSheet, I believe you must have Professional version for that. You will just want to add a TImage *Image variable to the class. Then initialize it in the constructor.

Set some __property's in order to work with it from the Object Inspector. One property might be the Transparent property of the TImage. Another would be whether it's visible or not. And third you would want a property for the Graphics::TBitmap* that is displayed.

If you have written components, it shouldn't be TOO hard to figure out. Let me know if you need further instruction.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top