2

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 enter image description herea solution for this? Thanks in advance. Follows a brief descriptive image:

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
user2383818
  • 709
  • 1
  • 8
  • 19
  • Just paint that title area by yourself and do not use a subcomponent for that – Sir Rufo Nov 24 '13 at 09:23
  • I understand sometimes we want to write the component ourselves to learn and to build specific functionalities, however, you this detail in your component becomes a real problem, you can try `TjvCaptionPanel` in Jedi (http://sourceforge.net/projects/jcl/). It's a panel with a caption with some very nice features. – AlexSC Nov 24 '13 at 20:07
  • 1
    The problem is nicely illustrated! – Edwin Yip May 17 '14 at 04:40

2 Answers2

5

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

Community
  • 1
  • 1
kobik
  • 21,001
  • 4
  • 61
  • 121
1

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 .

S.MAHDI
  • 1,022
  • 8
  • 15