Python DelphiVCL GUI应用中Panel组件边距设置无效如何解决?
解决DelphiVCL for Python中Panel边距不生效的问题
问题核心:当Panel设置Align = "alClient"时,默认不会启用边距计算,需要开启AlignWithMargins属性才能让Margins设置生效。
修复步骤
- 在设置
self.myPanel.Align = "alClient"之后,添加一行代码开启边距对齐:self.myPanel.AlignWithMargins = True
修改后的完整代码
from delphivcl import * class frmMain(Form): def __init__(self, owner): self.Caption = 'Hello World' self.Width = 1000 self.Height = 500 self.Position = "poScreenCenter" self.myPanel = Panel(self) self.myPanel.Parent = self self.myPanel.Align = "alClient" # 开启边距对齐,使Margins设置生效 self.myPanel.AlignWithMargins = True self.myPanel.Margins.Top = 100 self.myPanel.Margins.Right = 100 self.myPanel.Margins.Bottom = 100 self.myPanel.Margins.Left = 100 self.myPanel.Caption = "Hello World!" self.myPanel.Font.Size = 30 self.myPanel.StyleElements = "" self.myPanel.Color = "$00D2E525"
原理说明
DelphiVCL中,Margins属性只有在控件的AlignWithMargins设为True时,才会在使用Align属性对齐时生效。默认该属性为False,所以即使设置了边距,控件依然会填满父容器的客户区。
内容的提问来源于stack exchange,提问作者Shaun Roselt
相关产品推荐
相关产品推荐

