I have a custom component based on a TPanel. The aim is to display at the top, a so called "title area", wich displays a caption and has customizable border and background color. It works fine, except for a little issue: at design time, when clicking on the "title area", the component is not selected (blue bullets doesn't appear), meaning that I can't drag or modify the component's properties. If I click outside the "title area", the component is selected. Can anyone have a solution for this? Thanks in advance. Follows a brief descriptive image:
2 Answers
5
votes
For the title panel set (e.g.):
constructor TMyTitlePanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csAcceptsControls] + [csNoDesignVisible];
end;
Another option is to use SetSubComponent(True)
for the title panel: https://stackoverflow.com/a/9479909/937125
1
votes
I think that is a bug from the IDE .. I tested this unit , and it's works as expected (using subcomponent ):
unit uMyPanel;
interface
uses
System.SysUtils, System.Classes,
Vcl.Controls, Vcl.ExtCtrls, WinApi.Messages;
type
TMyPanel = class(TPanel)
private
{ Private declarations }
FSubPanel: TPanel;
procedure WMWindowPosChanged(var Message: TWMWindowPosChanged);
message WM_WINDOWPOSCHANGED;
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMyPanel]);
end;
{ TMyPanel }
const
FSubPanelHeight = 30;
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited;
FSubPanel := TPanel.Create(Self);
FSubPanel.Parent := Self;
FSubPanel.Width := Width;
FSubPanel.Height := FSubPanelHeight;
FSubPanel.Caption := 'Title';
FSubPanel.Color := $00F4EBE2;
FSubPanel.Font.Color := $00B68C59;
Caption := '';
ShowCaption := False;
Height := 100;
Color := $00F4EBE2;
end;
destructor TMyPanel.Destroy;
begin
if Assigned(FSubPanel) then
FSubPanel.Destroy;
inherited;
end;
procedure TMyPanel.WMWindowPosChanged(var Message: TWMWindowPosChanged);
begin
inherited;
FSubPanel.Width := Width;
end;
end.
if this Component TMyPanel
has the same problem in your delphi IDE .. then it's probably a bug ,since this Component was tested using XE3 and i have not experienced this problem .
Note : this is only a test .. you should do what @Sir Rufo suggested .
TjvCaptionPanel
in Jedi (sourceforge.net/projects/jcl). It's a panel with a caption with some very nice features. – AlexSC