Compound component selection box not executed correctly

I have a composite component consisting of TEdit and TButton (yes, I know about TButtonedEdit ) that inherits from TCustomControl . Editing and a button are created in its constructor and placed on it.

At design time, the selection box is not drawn correctly - I assume that the edit button hides it because it was drawn for a user control and then dragged them.

Here's a comparison:

enter image description here

I also saw this for other third-party components (for example, TcxGrid also draws only the outside of the selection indicator)

Question: How can I change this?

The easiest case to play:

 unit SearchEdit; interface uses Classes, Controls, StdCtrls; type TSearchEdit = class(TCustomControl) private fEdit: TEdit; public constructor Create(AOwner: TComponent); override; end; procedure Register; implementation procedure Register; begin RegisterComponents('Custom', [TSearchEdit]); end; { TSearchEdit } constructor TSearchEdit.Create(AOwner: TComponent); begin inherited; fEdit := TEdit.Create(Self); fEdit.Parent := Self; fEdit.Align := alClient; end; end. 
+6
source share
1 answer

As I said in the comments, the easiest thing I can think of is to draw the controls in the parent element and β€œhide” them from the designer during development. You can do this by calling SetDesignVisible (False) for each of the child controls. Then you can use PaintTo to paint the parent.

Using your example, we get:

 type TSearchEdit = class(TCustomControl) ... protected procedure Paint; override; ... end; constructor TSearchEdit.Create(AOwner: TComponent); begin inherited; fEdit := TEdit.Create(Self); fEdit.Parent := Self; fEdit.Align := alClient; fEdit.SetDesignVisible(False); end; procedure TSearchEdit.Paint; begin Inherited; if (csDesigning in ComponentState) then fEdit.PaintTo(Self.Canvas, FEdit.Left, FEdit.Top); end; 
+3
source

All Articles