繁体   English   中英

Delphi自定义TPanel组件

[英]Delphi custom TPanel component

我有一个基于TPanel的自定义组件。 目的是在顶部显示一个所谓的“标题区域”,其中显示标题并具有可自定义的边框和背景色。 它工作正常,除了一个小问题:在设计时 ,单击“标题区域”时,未选择组件(没有蓝色项目符号出现),这意味着我无法拖动或修改组件的属性。 如果我在“标题区域”之外单击,则选择该组件。 任何人都可以 在此处输入图片说明 一个解决方案? 提前致谢。 跟随一个简短的描述性图像:

对于标题面板集(例如):

constructor TMyTitlePanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csAcceptsControls] + [csNoDesignVisible];
end;

另一个选项是将SetSubComponent(True)用于标题面板: https : SetSubComponent(True)

我认为这是来自IDE的错误。我测试了此单元,并且按预期方式工作(使用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.

如果此组件TMyPanel在您的delphi IDE中存在相同的问题..则可能是一个错误,因为此组件已使用XE3进行了测试,而我没有遇到此问题。

注意:这仅是测试..您应该做@Sir Rufo建议的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM