JeffBurroughs 0 Posted June 9, 2020 When a form has a lot of components there is noticeable flickering when it is being painted when themes are applied. When you spend considerable effort making your program flicker free this is annoying. Any tricks or tips to stop or hide the flicker when a form is being shown? Latest Delphi 10.4. Share this post Link to post
Attila Kovacs 631 Posted June 9, 2020 (edited) You could play around with the LockWindowUpdate(Form.Handle); / LockWindowUpdate(0); and/or with the Form.Perform(WM_SETREDRAW, Winapi.Windows.wParam(LongBool(False)), 0); / Form.Perform(WM_SETREDRAW, Winapi.Windows.wParam(LongBool(True)), 0); pairs. I'm using them in OnDPIChange. It will also give a delay for showing the form. Edited June 9, 2020 by Attila Kovacs Share this post Link to post
Anders Melander 1815 Posted June 9, 2020 45 minutes ago, Attila Kovacs said: You could play around with the LockWindowUpdate(Form.Handle); / LockWindowUpdate(0); That is some really bad advice. https://devblogs.microsoft.com/oldnewthing/20070219-00/?p=27963 (read all 4 articles in the series) 1 Share this post Link to post
JeffBurroughs 0 Posted June 9, 2020 At the moment when I have some form updating code I want to hide I will use alphablend to hide form painting. Basically set alpha to 0, do your painting/resizing/etc, then set alpha to 255. This stops all the problems with "Cannot do xyz on form.show" type errors if you just set visible to false then true. The form then takes slightly longer to show (milliseconds), but it appears flicker free after all the control drawing is done with alpha 0. The problem with the styles is that the restyling seems to fire after onshow finishes so there is no way I can "hide" it repainting all the controls and having the flicker. If there was a "OnAfterStyling" event or even a "OnFormDoneGettingReady" event that fired after all the oncreate, onshow, styling, etc was all finished. Personally I think the styles are a gimmick, but since adding support for them my users love them. Share this post Link to post
Vincent Parrett 764 Posted June 10, 2020 Styles cause all sorts of flicker problems - I'm pulling my hair out dealing with flicker that was introduced somewhere between XE7 and 10.4 (I'm upgrading from XE7) - really wishing I had never bothered with styles! FWIW, the IDE also has many flicker issues - the whole VCL/styles thing is a mess, but they can't be bothered to fix it because marketing can't put that "on the box"! Share this post Link to post
JeffBurroughs 0 Posted June 10, 2020 I do leave styles disabled by default and give the user options to enable/disable them. That way at least I have a "fix" for when someone complains the UI flickers badly. Here's hoping they do spend more time on theming and styles in the future. Adding an event that triggered once styling is applied would be enough for me to have a work around flicker fix. Share this post Link to post
Uwe Raabe 2064 Posted June 10, 2020 As most styles do paint a TPanel (and other container contorls) with the style color anyway, it doesn't make any difference if the panel has its ParentBackground property set or not. Setting it to false usually reduces the flickering significantly. Share this post Link to post
Darian Miller 366 Posted June 10, 2020 15 hours ago, Vincent Parrett said: Styles cause all sorts of flicker problems - I'm pulling my hair out dealing with flicker that was introduced somewhere between XE7 and 10.4 (I'm upgrading from XE7) - really wishing I had never bothered with styles! FWIW, the IDE also has many flicker issues - the whole VCL/styles thing is a mess, but they can't be bothered to fix it because marketing can't put that "on the box"! For what it's worth, setting the VCL style in the DPR before the forms are created does seem to help with flicker (if you aren't already doing that.) Share this post Link to post
JeffBurroughs 0 Posted June 10, 2020 9 hours ago, Uwe Raabe said: As most styles do paint a TPanel (and other container contorls) with the style color anyway, it doesn't make any difference if the panel has its ParentBackground property set or not. Setting it to false usually reduces the flickering significantly. Thanks for the tip, but that doesn't seem to make any noticeable difference here. For example, I have a groupbox with lots of checkboxes inside. Setting the groupbox parentbackground to false does not help the visible drawing and flicker of the checkboxes when the form is shown. The flickering probably only lasts 200ms or less but it is obvious and happens every time a styled form is shown. The forms are already doublebuffered:=true which does help non-styled flicker but has no effect on reducing styled UI flicker. Share this post Link to post
JeffBurroughs 0 Posted June 10, 2020 3 hours ago, Darian Miller said: For what it's worth, setting the VCL style in the DPR before the forms are created does seem to help with flicker (if you aren't already doing that.) That would force you to have only 1 style always on though right? There is no way to have a DPR defined style but then allow the user to select another style or disable styling. Share this post Link to post
Vincent Parrett 764 Posted June 10, 2020 6 hours ago, Darian Miller said: For what it's worth, setting the VCL style in the DPR before the forms are created does seem to help with flicker (if you aren't already doing that.) I do that (well not in the dpr, but before any forms are shown). Share this post Link to post
JeffBurroughs 0 Posted June 10, 2020 1 hour ago, Vincent Parrett said: I do that (well not in the dpr, but before any forms are shown). When a style is changed I only set a global stylemanager style, ie stylemanager.TrySetStyle(stylename,true); Other forms then get that style automatically applied when they are created and shown. No need to set the style specifically as each form is created. Share this post Link to post
Vincent Parrett 764 Posted June 10, 2020 3 minutes ago, JeffBurroughs said: When a style is changed I only set a global stylemanager style, ie stylemanager.TrySetStyle(stylename,true); Other forms then get that style automatically applied when they are created and shown. No need to set the style specifically as each form is created. Yes, that's what I'm doing, not before each form.. just before the first form (splash screen) is shown. I just don't do it in the dpr, since I need to check the user's config to see which theme is selected first. My dpr literally had 1 line (apart from uses etc) begin TIDEStartup.Run(); end. That does mean however that the Appearance node in the project options doesn't show - so I have to manually add the styles to a resource file - not a big deal though. Share this post Link to post
Mahdi Safsafi 225 Posted June 11, 2020 @Vincent Parrett Quote the whole VCL/styles thing is a mess, but they can't be bothered to fix it because marketing can't put that "on the box"! It's not like they do not bother them-self to make a fix. The problem is that its a hard thing to do (at least if you want to stay native). The OS(Windows) is not helping at all ! I developed Vcl-styling for MainMenu/PopupMenu and system-dialogs theming with RRUZ(you may find a licence in Vcl.Themes unit). I can guarantee you that the big deal with styling Windows components is coming from the Windows side! MS for unknown reason does not want you to do that, and hides/un-document all the important parts ... forcing you to do painting in an ugly way which can cause flicker and all Vcl-styles related issues. A sometime ago, I was working internally on a native, better solution that implies using DDetours, For many components, it gave a much better result, a smooth, native drawing that has nearly zero cost overhead(I experienced no flicker, Scrollbars were true native -not as the current implementation-). Unfortunately, I got a very little time to work on that project and ended-up abandon/forgotten. Conclusion : If you want someone to blame ... blame MS. Share this post Link to post