如何禁止Python FMX GUI Form窗口被调整大小?
解决方案:禁止DelphiFMX窗口调整大小并隐藏最大化按钮
要实现需求,只需在Form的初始化方法中添加两个关键设置:
- 隐藏最大化按钮:修改
BorderIcons属性,移除biMaximize枚举值,仅保留需要的窗口控件(比如系统菜单和最小化按钮)。 - 禁止拖拽调整大小:通过
Constraints属性固定窗口的宽高范围,让最小、最大宽高等于窗口初始尺寸,彻底锁定大小;也可以直接设置BorderStyle为固定样式(如bsDialog)。
修改后的完整代码
from delphifmx import * class frmMain(Form): def __init__(self, owner): self.Caption = 'My Form' self.Width = 1000 self.Height = 500 # 隐藏最大化按钮,保留系统菜单和最小化按钮 self.BorderIcons = [biSystemMenu, biMinimize] # 固定窗口宽高,禁止拖拽调整 self.Constraints.MinWidth = self.Width self.Constraints.MaxWidth = self.Width self.Constraints.MinHeight = self.Height self.Constraints.MaxHeight = self.Height def main(): Application.Initialize() Application.Title = "My Application" Application.MainForm = frmMain(Application) Application.MainForm.Show() Application.Run() Application.MainForm.Destroy() main()
可选方案:使用边框样式固定大小
如果你更偏好通过窗口边框样式实现固定效果,可以将上述代码中Constraints相关的设置替换为:
self.BorderStyle = bsDialog
这种方式下窗口会采用对话框样式,默认无法调整大小且无最大化按钮,但窗口的边框和系统菜单样式会与普通窗口略有区别。
内容的提问来源于stack exchange,提问作者Shaun Roselt
相关产品推荐
相关产品推荐

