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!

How do I draw on top of a TPanel ? 1

Status
Not open for further replies.

cppdev

Programmer
May 12, 2003
23
US
How do i draw on top of a TPanel ? do i declare a Canvas somewhere such that it is on top of the Panel?

thanks in advance.
 
TPanel won't allow it. You would have to drop a TImage or create a TImage with that panel as it's parent and owner. Then draw on the TImage's canvas. I can't remember, you may have to draw on the TImage->Picture->Bitmap->Canvas.

Chris
 
I am trying to provide a graphical front end for a proprietary programming language. I need to be able to display 40 rows and 31 columns in the panel. then i need to be able to select a string of character spaces and then specify field (int, char, decimal, etc.. ) type this area will represent....but i dont actually enter data of a specific field type....it is just a gui to use the specified parameters to generate code for a specific field type at a specific location when the code is generated.

Do you think Paintbox, or TImage would be best for this? or is there a better alternative.

I need to keep this as general as possible for future modification, there will probably be a modified painting method in the future and i do not know what else will be changed.


Thanks for the help.



 
TPaintBox won't get you anymore than TImage does. Unless you want to be able to free hand draw...which I don't think you do. I don't really follow what you need it for(been a long week at work), so I can't suggest anything better.
 
You can access the Panel's canvas property like so,

in the Form's header file declare

class TPanelCanvasHack : public TPanel
{
public:
__property Canvas;
};

then in the cpp
((TPanelCanvasHack*)Panel1)->Canvas->TextOut....

Another method which I haven't tried

HWND hwnd = Panel1->Handle;

HDC hdc = GetDC( hwnd );
TCanvas* Canvas = new TCanvas();
Canvas->Handle = hdc;
Canvas->TextOut... and/or all other drawing methods
delete Canvas;
ReleaseDC(hwnd, hdc);


If you're creating your own component derived from a TPanel then you can override the Panel's inherited Paint() method and do your own drawing there.


 
To create my own paint routine, should I create a component?

Thanks for the advice on hacking the canvas. It works Perfect!!


Thanks in Advance,
 
Hi cppdev :)

If you plan on using this panel in many other places then sure or sharing it then sure, a component will make it easier to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top