how is it possible to clear what was painted before?
I'm using Delphi and I'm building my own label component with class TControl. Before I paint the text according to the properties (such as caption, font, etc.) I want to clear pa开发者_运维问答int rect like there is nothing at the place of component. I mean I want to make it like a glass so that the other components behind it will be displayed; and then paint the text. What should I do to paint other components that are placed behind my label to it?
To do that, you need to do nothing. :-)
When you make a transparent label-like component, you best use the TGraphicControl base class. This is actually little more than a canvas to paint on. Whenever the content should be changed, you call the Invalidate
method to repaint your control. This will call the Paint
method that you can override. With every repaint, your control will be clear and transparent, except for the parts where you draw stuff in your Paint
method.
Unless you override and disable the background painting, then you dont need to do anything. It depends on what base-class you go for. Although you can simply use (in the Paint() method):
Canvas.Brush.Style:=bsSolid;
Canvas.Brush.Color:=self.Color; //If you have a public color property
Canvas.FillRect(ClientRect);
You should also read up on TControlCanvas. Here is a website that deals with this topic more in depth: http://www.delphidabbler.com/tips/75
精彩评论