zoukankan      html  css  js  c++  java
  • 使用剪切板[4]: 如果把子控件一起复制? 同时回复 ghd2004 的问题

    如果连同子控件一起复制到剪切板, 需要定义一个新类型.

    譬如在一个 TPanel 中包含一个 TEdit; 在复制 TPanel 时, 若要连同 TEdit 一起复制, 需要重新从 TPanel 中继承出一个类来(譬如是 TMyPanel), 把 TEdit 包含在新的类中.

    运行效果图:



    TMyPanel 类的单元:
    unit MyPanel;
    
    interface
    
    uses Classes, StdCtrls, ExtCtrls;
    
    type
      TMyPanel = class(TPanel)
        Edit1: TEdit; 
        constructor Create(AOwner: TComponent); override;
      end;
    
    implementation
    
    { TMyPanel }
    
    constructor TMyPanel.Create(AOwner: TComponent);
    begin
      inherited;
      Edit1 := TEdit.Create(Self);
      Edit1.Parent := Self;
      Edit1.Left := 10;
      Edit1.Top := 10;
      RegisterClasses([TMyPanel]); {在这里就给注册了}
    end;
    
    end.
    
    测试单元:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses Clipbrd, MyPanel;
    
    var
      obj: TComponent;
      pnl: TMyPanel;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      pnl := TMyPanel.Create(Self);
      pnl.Parent := Self;
      pnl.Edit1.Text := '一起被复制';
    
      Button1.Caption := '复制';
      Button2.Caption := '粘贴';
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Clipboard.SetComponent(pnl);
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      if Clipboard.HasFormat(CF_COMPONENT) then
      begin
        obj := Clipboard.GetComponent(Self, Self);
        TMypanel(obj).Left := 20;
        TMypanel(obj).Top := 60;
      end;
    end;
    
    end.
    
  • 相关阅读:
    make、make clean、make install、make uninstall、make dist、make distcheck和make distclean
    Eclipse开发C/C++ 安装配置
    没有文件扩展“.js”的脚本引擎问题解决
    Linux目录架构详解
    Linux查看硬件信息以及驱动设备的命令
    23种设计模式彩图
    ACE在Linux下编译安装
    void及void指针含义的深刻解析
    centos7.x设置nginx开机自启动
    Centos7防火墙关闭和启用iptables操作
  • 原文地址:https://www.cnblogs.com/del/p/1137617.html
Copyright © 2011-2022 走看看