如何有效地让一个“ParentFont = False”子控件使用与父母相同的字体名称?
如何有效地让一个“ParentFont = False”子控件使用与父母相同的字体名称?(How to efficiently let a `ParentFont = False` child control to use same font name as parent?)
Most VCL controls has Fonts and ParentFont property. It is a good practice to set ParentFont = True and the Fonts will follow it's parent font's Name, Height and Color. This give a uniform visual among controls.
However, we may want to make one or two controls to have different looks from other by setting Font.Style = fsBold or a contrast Font.Color but using same Font.Name as parent's font. Doing so makes ParentFont = false. From this point onward, changing parent's font name or size will have no effects on those control's font property.
I think this might be VCL's design. Perhaps someone has better design practices or experience to share on Fonts and ParentFont issue.
Consider a case where I let user set a default font name for the application. Those ParentFont = False controls will not change accordingly. Manual override in coding is possible but it is tedious work that introduce extra coding.
That is known VCL limitation.
You can either have ParentFont or your custom font settings in which case changing font properties in parent will not be propagated.
The best way around that is to use ParentFont = true everywhere and set custom font properties of specific controls at runtime in form's OnCreate event. Of course, in that case you lose What You See Is What You Get at design time, but you get more control over actual runtime appearance of your forms.
procedure TForm1.OnCreate(Sender: TObject);
begin
inherited;
Label1.Font.Style := [fsBold];
Label1.Font.Color := clRed;
end;
For applying user custom font selection, you would also need to recreate forms, or use ParentFont := true before applying custom styles for specific controls, so they pick up your new font settings.
本文地址:IT屋 » How to efficiently let a `ParentFont = False` child control to use same font name as parent?
大多数VCL控件具有字体和 ParentFont 属性。设置 ParentFont = True 是一个很好的做法,字体将跟随它的父字体的名称,高度和颜色。这样可以在控件之间提供统一的视觉效果。
但是,我们可能希望通过设置 Font来使一个或两个控件与其他控件不同。 Style = fsBold 或对比 Font.Color ,但使用相同的 Font.Name 作为父级字体这样做会使 ParentFont = false 。从此以后,更改父母的字体名称或大小将对这些控件的字体属性没有影响。
我认为这可能是VCL的设计。也许有人有更好的设计实践或经验来分享Fonts和ParentFont问题。
考虑一个例子,我让用户为应用程序设置一个默认的字体名称。那些 ParentFont = False 控件不会相应改变。编码中的手动覆盖是可行的,但是引入额外的编码是繁琐的工作。
这是已知的VCL限制。
您可以拥有 ParentFont 或您的自定义字体设置,在这种情况下,更改父级中的字体属性将不会被传播
最好的办法是使用 ParentFont = true ,并设置特定控件的自定义字体属性运行时在窗体的 OnCreate 事件。当然,在这种情况下,您将在设计时失去您所看到的是您所获得的,但您可以更好地控制表单的实际运行时外观。
procedure TForm1.OnCreate(Sender:TObject);
开始
继承;
Label1.Font.Style:= [fsBold];
Label1.Font.Color:= clRed;
结束
为了应用用户自定义字体选择,您还需要重新创建表单,或使用 ParentFont:= true 在应用特定控件的自定义样式之前,以便他们选择您的新字体设置。
如何有效地让一个“ParentFont = False”子控件使用与父母相同的字体名称?的更多相关文章
- WPF silverlight获取子控件(获取DataTemplate里的子控件)
public static class VisualTreeExtensions { /// <summary> /// 获取父节点控件 /// </summary> /// ...
- 记录下帮助一位网友解决的关于android子控件的onTouch或onClick和父OnTouch 冲突的问题。
前三天收到位网友的私信求助,问题大概如标题所示.具体是下面的情况,个人感觉,这个问题挺有趣,也会在实际项目开发中很常见.不想看前奏的请直接跳至解决方法. 问题原型: 父控件是自定义的 LinearLa ...
- ParentWindow属性及其一系列函数的作用——适合于那些不需要父控件管理内存释放的子控件
TWinControl = class(TControl) property ParentWindow: HWnd read FParentWindow write SetParentWindow; ...
- OnClick事件的Sender参数的前世今生——TWinControl.WinProc优先捕捉到鼠标消息,然后使用IsControlMouseMsg函数进行消息转发给图形子控件(意外发现OnClick是由WM_LBUTTONUP触发的)
这是一个再普通不过的Button1Click执行体: procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage('I am B ...
- 五种情况下会刷新控件状态(刷新所有子FWinControls的显示)——从DFM读取数据时、新增加子控件时、重新创建当前控件的句柄时、设置父控件时、显示状态被改变时
五种情况下会刷新控件状态(刷新控件状态才能刷新所有子FWinControls的显示): 在TWinControls.PaintControls中,对所有FWinControls只是重绘了边框,而没有整 ...
- 解决ListView中Item的子控件与Item点击事件冲突
常常会碰到在ListView中点击当中一个Item.会一并触发其子控件的点击事件.比如Item中的Button.ImageButton等.导致了点击Item中Button以外区域也会触发Button点 ...
- 截取scrollview的滑动事件,传递给子控件
重写一个ScrollView public class MyScrollView extends ScrollView{ public MyScrollView(Context context, At ...
- TCustomControl绘制自己和图形子控件共四步,TWinControl关键属性方法速记
TCustomControl = class(TWinControl) private FCanvas: TCanvas; procedure WMPaint(var Message: TWMPain ...
- 初步探讨WPF的ListView控件(涉及模板、查找子控件) - GavinJun
本文结合模板的应用初步介绍ListView的应用 一.Xaml中如何建立数据资源 大部分数据都会来自于后台代码,如何Xaml同样的建立数据源呢?比如建立一个学生List: 首先引入命名空间: xmln ...
随机推荐
- QGIS里的编程模型
项目(QgsProject) 用于读写项目状态 图层分组(QgsLayerTreeGroup) 项目树的分组节点,用来存放图层节点. 图层节点(QgsLayerTreeLayer) 项目树的图层节点. ...
- WorldWind源码剖析系列:绘制参数类DrawArgs
绘制参数类DrawArgs主要对绘制时需要的对象如:设备对象Microsoft.DirectX.Direct3D.Device.Microsoft.DirectX.Direct3D.Font字体对象. ...
- 几个PHP读取整个文件的函数readfile()、fpassthru()和file()
2.7.4 读取整个文件:readfile().fpassthru()和file()除了可以每次读取文件一行外,还可以一次读取整个文件.PHP提供了4种不同的方式来读取整个文件.第一种方式是rea ...
- AS3.0 自定义右键菜单类
AS3.0 自定义右键菜单类: /** * 自定义右键菜单类 * 自定义菜单项不得超过15个,每个标题必须至少包含一个可见字符. * 标题字符不能超过100个,并且开头的空白字符会被忽略. * 与任何 ...
- python 回溯法 子集树模板 系列 —— 4、数字组合问题
问题 找出从自然数1.2.3.....n中任取r个数的所有组合. 例如,n=5,r=3的所有组合为: 1,2,3 1,2,4 1,2,5 1,3,4 1,3,5 1,4,5 2,3,4 2,3,5 2 ...
- openssh7.9 升级笔记
由于全网安全检查需要,要对项目中1280台Linux系统升级SSH及openssl,其中: OPENSSH 升级为 openssh 7.9p 下载地址: openssl 升级为 1.0.2o 下载地 ...
- [计算机视觉] 图像拼接 Image Stitching
[计算机视觉] 图像拼接 Image Stitching 2017年04月28日 14:05:19 阅读数:1027 作业要求: 1.将多张图片合并拼接成一张全景图(看下面效果图) 2.尽量用C/C+ ...
- JavaScript快速入门-ECMAScript本地对象(Array)
Array对象 Array对象和python里面的list对象一样,是用来存储多个对象值的对象,且方法和属性基本上类似. 一.属性 lenght 二.方法 1.concat() 用于连接两个或多个 ...
- svn插件下载的两种方式
1.下载SVN插件 SVN插件下载地址及更新地址,你根据需要选择你需要的版本.现在最新是1.8.x Links for 1.8.x Release: Eclipse up ...
- 外网主机访问虚拟机下的web服务器(NAT端口转发)-----端口映射
主机:系统win7,ip地址172.18.186.210 虚拟机:VMware Workstation 7,虚拟机下安装了Centos操作系统,ip地址是192.168.202.128,部署了LAMP ...