Thread View: borland.public.cppbuilder.multimedia
3 messages
3 total messages
Started by Joseph
Wed, 05 Mar 2003 06:03
How do I draw on TCanvas from inside a function call ?
Author: Joseph
Date: Wed, 05 Mar 2003 06:03
Date: Wed, 05 Mar 2003 06:03
41 lines
2367 bytes
2367 bytes
Hello All,
Is it possible to draw on TControlCanvas from inside a function call ?
I mean ...
void __fastcall TForm1::ShowTabSheet (Object *Sender) {
TControlCanvas *pCanvas = new TControlCanvas ;
pCanvas->Control = Tabsheet ; // ie., TForm1::Tabsheet. Need to draw
// on TabSheet, not on the main Form.
DrawOnCanvas ( pCanvas ) ; //** I need to draw on pCanvas from here
delete pCanvas ;
};
void TForm1::DrawOnCanvas ( TControlCanvas *CANVAS ) {
CANVAS->Pen->Color = clBlue ;
CANVAS->MoveTo(0,0);
CANVAS->LineTo(100,200);
};
... This compiles and Links OK, but when I run it I get an error
message saying that "Canvas does not allow drawing". If I do the
drawing from inside the calling function, it's ok. But if done via a
function call, it won't draw.
Is the above the appropriate way of drawing on TControlCanvas from
inside a function ?
Regards,
Joseph 76
Re: How do I draw on TCanvas from inside a function call ?
Author: Maynard Philbrook
Date: Wed, 05 Mar 2003 07:14
Date: Wed, 05 Mar 2003 07:14
41 lines
2708 bytes
2708 bytes
pCanvas->Canvas->?????
Joseph wrote:
> Hello All,
>
> Is it possible to draw on TControlCanvas from inside a function call ?
>
> I mean ...
>
> void __fastcall TForm1::ShowTabSheet (Object *Sender) {
>
> TControlCanvas *pCanvas = new TControlCanvas ;
>
> pCanvas->Control = Tabsheet ; // ie., TForm1::Tabsheet. Need to draw
> // on TabSheet, not on the main Form.
>
> DrawOnCanvas ( pCanvas ) ; //** I need to draw on pCanvas from here
>
> delete pCanvas ;
> };
>
> void TForm1::DrawOnCanvas ( TControlCanvas *CANVAS ) {
>
> CANVAS->Pen->Color = clBlue ;
> CANVAS->MoveTo(0,0);
> CANVAS->LineTo(100,200);
>
> };
>
> ... This compiles and Links OK, but when I run it I get an error
> message saying that "Canvas does not allow drawing". If I do the
> drawing from inside the calling function, it's ok. But if done via a
> function call, it won't draw.
>
> Is the above the appropriate way of drawing on TControlCanvas from
> inside a function ?
>
> Regards,
> Joseph 76
Re: How do I draw on TCanvas from inside a function call ?
Author: Joseph
Date: Thu, 06 Mar 2003 23:34
Date: Thu, 06 Mar 2003 23:34
81 lines
3622 bytes
3622 bytes
Ok I worked it out. The reason why I was getting "Cannot Draw on
Canvas" runtime message is that CANVAS parameter inside the function
points to a TControlCanvas "interface" but nothing to draw on (ie., to
real device context). So this is the fix ...
void TForm1::DrawOnCanvas ( TControlCanvas *CANVAS ) {
CANVAS = new TControlCanvas ;
CANVAS->Control = Tabsheet ; // draw on Tabsheet
CANVAS->Pen->Color = clBlue ;
CANVAS->MoveTo(0,0);
CANVAS->LineTo(100,200);
delete CANVAS ;
};
Actually, I don't even need to pass in a TControlCanvas parameter, so
the function can be simplified to this ...
void TForm1::DrawOnCanvas ( ) {
TControlCanvas *CANVAS = new TControlCanvas;
CANVAS->Control = Tabsheet ; // draw on Tabsheet
CANVAS->Pen->Color = clBlue ;
CANVAS->MoveTo(0,0);
CANVAS->LineTo(100,200);
delete CANVAS ;
};
Cheers,
Joseph 76.
joseph.redimerio@baesystems.com (Joseph) wrote in message news:<7b424d28.0303042203.21e36935@posting.google.com>...
> Hello All,
>
> Is it possible to draw on TControlCanvas from inside a function call ?
>
> I mean ...
>
> void __fastcall TForm1::ShowTabSheet (Object *Sender) {
>
> TControlCanvas *pCanvas = new TControlCanvas ;
>
> pCanvas->Control = Tabsheet ; // ie., TForm1::Tabsheet. Need to draw
> // on TabSheet, not on the main Form.
>
> DrawOnCanvas ( pCanvas ) ; //** I need to draw on pCanvas from here
>
> delete pCanvas ;
> };
>
>
>
> void TForm1::DrawOnCanvas ( TControlCanvas *CANVAS ) {
>
> CANVAS->Pen->Color = clBlue ;
> CANVAS->MoveTo(0,0);
> CANVAS->LineTo(100,200);
>
> };
>
>
> ... This compiles and Links OK, but when I run it I get an error
> message saying that "Canvas does not allow drawing". If I do the
> drawing from inside the calling function, it's ok. But if done via a
> function call, it won't draw.
>
> Is the above the appropriate way of drawing on TControlCanvas from
> inside a function ?
>
>
>
> Regards,
> Joseph 76
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads