I need to draw on a TPanel, ideally directly so I don't have another component on top of it getting in the way of mousevent-event trapping (I want to draw a little "size-grip" on it). How should I go about doing this?
How to draw on a TPanel
26.7k views Asked by Jamo At
4
There are 4 answers
4
On
This is one of the many many ways that Raize Components can make your life easier. I just go into Delphi, drop on a TRzPanel, and type:
RzPanel1.Canvas.Rectangle...
I'm sure there are other solutions - but I don't have to look for them with Raize.
(just a satisfied customer for about 10 years...)
EDIT: Given your goal, and your statement that you have Raize Components already, I should also point out that TRzSizePanel handles resizing of the panel and useful events like OnCanResize (to determine whether you want to allow resizing to a particular new width or height).
0
On
How to Add Size Handles to Controls being Resized at Run-Time: http://delphi.about.com/library/weekly/aa110105a.htm
TAdvPanel: http://www.tmssoftware.com/site/advpanel.asp
To really do it right, you should probably write a descendant class. Override the
Paintmethod to draw the sizing grip, and override theMouseDown,MouseUp, andMouseMovemethods to add resizing functionality to the control.I think that's a better solution than trying to draw onto a
TPanelin your application code for a couple of reasons:Canvasproperty is protected inTPanel, so you have no access to it from outside the class. You can get around that with type-casting, but that's cheating.Here's something to get you started: