AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Delphi-PRAXiS - Lounge Delphi-News aus aller Welt Delphi FMX Desktop - Restrict Form Size on Windows and macOS
Thema durchsuchen
Ansicht
Themen-Optionen

Delphi FMX Desktop - Restrict Form Size on Windows and macOS

Ein Thema von DP News-Robot · begonnen am 16. Dez 2021
Antwort Antwort
Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
14.983 Beiträge
 
#1

Delphi FMX Desktop - Restrict Form Size on Windows and macOS

  Alt 16. Dez 2021, 03:40
I'm in the process of porting over an old VCL application to FMX. At this time I'm only concerned with creating a desktop application that will run on Windows and macOS. One of the VCL features I like is the ability to set the forms minimum width and height properties. This prevents the user from making the application ridiculously small and unusable.

With a VCL application this is accomplished by simply entering the desired values in the MinHeight and MinWidth propertiesof the forms Constraints. The example below sets the VCL forms minimum height to 540 and the minimum width to 720.


Unfortunately, these properties do not exist within FMX Muilti-Device applications. In order to impose size constraints in FMX you have to write some code in the OnResize event handler.

The simplest way to accomplish this would be to right some code similar to this:

procedure TForm1.FormResize(Sender: TObject); const MinW = 720; MinH = 540; begin if Width < MinW then Width := MinW; If Height < MinH then Height := MinH; end; This works. However it produces a horrible flickering effect when you continue to drag the mouse inside the boundaries specified within the OnResize event handler.

Windows Form Constraints with Flickering

What about the macOS? Does it flicker? The answer is no. The macOS respects the size constraints with no flickering issue:

macOS Form Constraints no Flickering


So the issue only happen on Windows PC's.
I may be oversensitive here but I do not like this flickering at all. In my mind it gives the sense of an unprofessional appearance. Some end users may not care one bit about this and that's fine. However, it really bugs me. I want to prevent this from happening.

So I went looking for a solution and found one on stackoverflow. The code simulates a mouseUp event if the cursor moves inside the boundaries.

Windows Form Constraints with No Flickering
This is accomplished by making a Windows API Mouse Event call inside the OnResize event handler. It's not perfect but it does prevent the flickering from happening.

Add this to the Uses clause
Winapi.Windows

Modify the onResize event handler to simulate the mouseUp event.

procedure TForm1.FormResize(Sender: TObject); const MinW = 720; MinH = 540; begin if Width < MinW then begin Width := MinW; mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); end; If Height < MinH then begin Height := MinH; mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); end end;


This code works great! It stops Windows PC's from flickering. However, we are not done yet. We have to wrap special tags around the Windows Only code so it is ignored by the macOS.
Modify the Uses clause as follows:

uses {$IFDEF MSWINDOWS} Winapi.Windows, {$ENDIF} System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls; Modify the onResize event handler as follows

procedure TForm1.FormResize(Sender: TObject); const MinW = 720; MinH = 540; begin if Width < MinW then begin Width := MinW; {$IFDEF MSWINDOWS} //prevent form flickering on resize below constraints mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); {$ENDIF} end; If Height < MinH then begin Height := MinH; {$IFDEF MSWINDOWS} //prevent form flickering on resize below constraints mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); {$ENDIF} end; end end; Stay tuned for more FMX Desktop discoveries.

Enjoy
Semper Fi
Gunny Mike
https://zilchworks.com





Weiterlesen...
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz