【问题标题】:Delphi custom TPanel componentDelphi自定义TPanel组件
【发布时间】:2013-12-08 10:45:43
【问题描述】:

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

【问题讨论】:

  • 自己绘制标题区域,不要使用子组件
  • 我知道有时我们想自己编写组件来学习和构建特定的功能,但是,您组件中的这个细节成为一个真正的问题,您可以在 Jedi 中尝试TjvCaptionPanel (@987654321 @)。这是一个带有标题的面板,具有一些非常好的功能。
  • 这个问题很好地说明了!

标签: delphi delphi-xe


【解决方案1】:

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

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

另一个选项是使用SetSubComponent(True) 作为标题面板:https://stackoverflow.com/a/9479909/937125

【讨论】:

    【解决方案2】:

    我认为这是来自 IDE 的错误 .. 我测试了这个单元,它按预期工作(使用子组件):

    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 的建议去做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      • 2018-03-22
      • 2013-04-26
      • 2015-12-06
      • 2021-12-23
      • 2015-08-18
      相关资源
      最近更新 更多