DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: liangjiping168
今日帖子: 15
在线用户: 20
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/9/22 0:23:01
标题:
VCL 的 TPanel 动态创建的改不了颜色? 浏览:788
加入我的收藏
楼主: procedure TForm1.Button1Click(Sender: TObject);
var
  APanel: TPanel;
begin
  Panel1.Color := $000080FF;
  Panel1.Font.Color := clWhite;

  APanel := TPanel.Create(Self);
  APanel.Name := 'adfa';
  APanel.Color := clRed;
  APanel.Parent := Self;

  APanel.Align := alTop;
end;

上面的代码,Panel1 是设计期拖过来的,代码改颜色成功。

后面那个 APanel 用代码动态创建,虽然也设置了颜色,但是它显示出来仍然是灰色。

这个是什么情况?我设置了 ParentColor := False; 也没用。而且这个值应该是默认就是 False 的。
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/9/22 0:25:27
1楼: 搞定了。

居然是 ParentBackgroundColor 默认是 True 导致。把它设置为 False 就可以了。
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/9/22 4:31:40
2楼: the magic occurs on "ControlStyle" definition:

procedure TForm1.Button1Click(Sender: TObject);
var
  MyPanel: TPanel;
begin
  MyPanel        := TPanel.Create(self);
  MyPanel.Parent := self;
  MyPanel.Left   := 10;
  MyPanel.Top    := 10;
  MyPanel.Color  := clBlue;
  // MyPanel.ParentBackground := false;
  // or
  // MyPanel.ControlStyle := MyPanel.ControlStyle - [csParentBackground];
end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/9/22 14:20:55
3楼: Thanks, emailx45.
----------------------------------------------
-
作者:
男 dacsd (ddd) ★☆☆☆☆ -
盒子活跃会员
2022/9/23 8:16:56
4楼: 学习了!
----------------------------------------------
-
作者:
男 tulater (tulater) ★☆☆☆☆ -
普通会员
2022/9/23 18:46:53
5楼: 学习了
----------------------------------------------
http://www.cnblogs.com/tulater/
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行89.84375毫秒 RSS