zoukankan      html  css  js  c++  java
  • Delphi 中 动态创建的Panel无法改变颜色的解决办法

    刚开始代码如下:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Panel: TPanel;
    begin
      Panel := TPanel.Create(Form1);
      Panel.Name := 'pnlPreVideo';
      Panel.Parent := Form1;
      Panel.OnClick := Panel1Click;
      MoveWindow(Panel.Handle, 10, 10, 100, 100, True);
    end;
    
    procedure TForm1.Panel1Click(Sender: TObject);
    begin
      if  (Sender as TPanel).Name ='pnlPreVideo' then
        (Sender as TPanel).Color := clGreen;
    end;

    单击时,颜色不变,问网友,原来是一个BUG,更正后代码如下:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Panel: TPanel;
    begin
      Panel := TPanel.Create(Form1);
      Panel.Name := 'pnlPreVideo';
      Panel.ParentBackground := False;
      Panel.Parent := Form1;
      Panel.OnClick := Panel1Click;
      MoveWindow(Panel.Handle, 10, 10, 100, 100, True);
    end;
    
    procedure TForm1.Panel1Click(Sender: TObject);
    begin
      if  (Sender as TPanel).Name ='pnlPreVideo' then
        (Sender as TPanel).Color := clGreen;
    end;
  • 相关阅读:
    跨数据库操作
    Windows 服务
    Linq To DataTable
    嵌入式软件应用程序开发框架浅见
    31.获取当前系统时间
    30 System类
    29. StringBuilder
    28. string类中方法练习
    27 string类中常用的方法列表
    26.String类(1)
  • 原文地址:https://www.cnblogs.com/jxgxy/p/3248408.html
Copyright © 2011-2022 走看看