如何有效地让一个“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 ...
随机推荐
- leetcode62—Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- (二) DRF 视图
DRF中的Request 在Django REST Framework中内置的Request类扩展了Django中的Request类,实现了很多方便的功能--如请求数据解析和认证等. 比如,区别于Dj ...
- MVC bundle的使用总结
在我们的项目里面充斥着很多静态文件,为了追求模块化.插件化很多静态文件都被设计成模块的方式或者被分解,在需要的时候在通过组合的方式在UI层上使用:这就带来一个问题,文件多了会影响浏览器加载页面的速度, ...
- DB2创建视图view
create view v_table1(col1,col2,col3...)--视图名(字段一,字段二,字段三...) as --后跟查询语句 select col1,col2,col3... fr ...
- js倒计时,页面刷新时,不会从头计时
最近不忙,瞎鼓捣...哈哈 这里利用了H5的本地存储 localStorage,取秒数直接用了php的time()方法,就懒得用js取了. 把第一次访问页面时的时间存在客户端,然后再刷新的时候,比较用 ...
- ZOJ3623:Battle Ships(全然背包)
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- mvn dependency:tree
jar依赖冲突解决实践 前言 随着功能的增多,各种中间件的引入.应用以来的各种jar的规模极具膨胀,出现jar冲突和Class冲突的问题层出不穷,让人不胜其扰.本文针对冲突,提供一个排查和定位问题的最 ...
- 2017-2018-2 20155203《网络对抗技术》Exp5 MSF基础应用
1.实践过程记录 1.1一个主动攻击实践,如ms08_067; msf > search ms08_067_netapi //查看可以用的工具 [!] Module database cache ...
- 20155301 《网络攻防》 Exp5 MSF基础应用
20155301 <网络攻防> Exp5 MSF基础应用 基础问题 1.用自己的话解释什么是exploit,payload,encode 答:exploit就是利用一些工具的,用来收集目标 ...
- WPF样式(Style)入门
原文:WPF样式(Style)入门 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_34802416/article/details/78231 ...