如何限制 FireMonkey 中的最小表单宽度?
如何限制 FireMonkey 中最小表单的宽度?在 VCL 中它曾经非常简单 - 它只在表单属性中具有 Max 和 Min 约束。
How do I restrict a minimum form's width in FireMonkey? It used to be so easy in VCL - it just had Max and Min constraints in forms properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
未来读者请注意:
这仅适用于 XE3 以下的版本,因为
Fmx::Platform::TPlatform
类在 XE3 中已被删除。感谢@Alain Thiffault 在评论中指出。原始帖子:
这是一个更复杂(但更优雅)的替代解决方案,定义一个完全自定义的 Form 类,您可以从中继承自己的...
将此文件存储为 FMX.ConstrainedForm.pas,将其添加到 Form 的“uses”部分,并修改表单的声明,而不是:
它说:
由于缺乏自定义设计(无论如何,这是一个“快速解决方案”),然后您需要按如下方式挂钩表单的 OnCreate 事件:
现在这个表格不允许用户将其宽度或高度设置为低于 400!
再次强调,无需对 FireMonkey 平台本身进行任何实质性更改,这是您目前可以获得的最好的版本!
Note for future readers:
This will only work for versions below XE3 because the
Fmx::Platform::TPlatform
class was removed in XE3. Thanks to @Alain Thiffault for pointing it out in the comments.Original Post:
Here's a more complicated (but more elegant) alternative solution, defining an entirely custom Form class from which you can inherit your own...
Store this file as FMX.ConstrainedForm.pas, add it to your Form's "uses" section, and modify the declaration of your form so that instead of:
it says:
Due to the lack of a custom designed (at this point anyway, this is a "quick solution"), you then need to hook your form's OnCreate event as follows:
Now this form will not allow the user to set its width or height below 400!
Again, without making some substancial changes to the FireMonkey Platform itself, this is the best you're going to get for now!
将其放置在表单的“OnResize”事件上,根据需要替换值。
当然,这不是世界上最好的解决方案,但它会帮助您渡过难关,直到重新引入这些属性!
上面的代码很容易更改为最大值或最小值的任意组合,所以玩得开心!
Place this on the form's "OnResize" event, replace the values as appropriate.
Granted, not the best solution in the world, but it'll get you by until the properties are reintroduced!
The above code is easy enough to change for any combination of maximums or minimums, so have fun!
LaKraven,模拟 mouseUp 事件来消除闪烁。
LaKraven, simulate a mouseUp event to get rid of that flickering.
刚刚发现
TForm
有一个Constraints
属性。非常适合我,不会闪烁。
Just found out
TForm
has aConstraints
property in Delphi 11.Works perfectly for me without flickering.
另外,对于 LaKraven 关于基于 FormResize 的解决方案的回答,请使用 ClientWidth 和 ClientHeight 而不是 Width 和 Height 以防止表单拉伸。
Additionally for LaKraven's answer about FormResize based solution, use ClientWidth and ClientHeight instead of Width and Height to prevent stretching of the form.
以下是 Sunec 答案的更新版本,以消除闪烁。
根据 MSDN Mouse_Event 已被取代,应使用 SendInput 代替:
https://learn.microsoft.com/ en-us/windows/win32/api/winuser/nf-winuser-mouse_event
Below is an updated version to Sunec's answer, to get rid of flickering.
According to MSDN Mouse_Event has been superseded and SendInput should be used instead:
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event
要总结上述内容以获得有用的答案,只需使用下面的代码:
To summery the above for a useful answer just use code below: