Splash form "in pieces" lazarus / 31-LCL ---------------------------------------------------------------------- dietmar · 2021-09-09 16:41 Hi! I designed a splash form with an image on it and a progress bar. Tested that on 2 different Notebooks. On the first one (where I designed it), I set Position to "poScreenCenter" and it just looks fine (resolution: 1600x900). On the second one (resolution: 1920x1080) I get 2 problems: 1. The Splash form is not in the center, but out of it. 2. The progress bar isn't on the form any more, but somewhere in the middle of the desktop!?! Does anyone have an explanation or even a solution for this behaviour? Thx, --Dietmar ---------------------------------------------------------------------- MarkMLl · 2021-09-09 17:05 No, but a good place to start would probably be in the Screen and ScreenInfo objects which allow you to get at the screen/monitor dimensions (with the caveat that I've not looked at this on Windows, only Linux/Solaris). MarkMLl ---------------------------------------------------------------------- winni · 2021-09-09 18:11 Hi! Not an explanation but a solution to center the SplashForm in the center: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TSplashForm1.FormCreate(Sender: TObject);begin  left := (Screen.Width - self.Width) div 2;  Top :=  (Screen.Height - self.height) div 2;end; And the progressbar: Make shure, that the parent of the progressbar is the SplashForm: Right click on the progressbar  --> Change Parent Winni ---------------------------------------------------------------------- dietmar · 2021-09-09 20:25 Thx, the centering now works... But unfortunately, the progress bar already has the form as parent. One crazy solution could be to calculate the position of the progress bar relatively to the form position... --Dietmar ---------------------------------------------------------------------- dietmar · 2021-09-09 20:32 No, doesn't work this way. If I change the Left and Top values of the progress bar, it is completely hidden and no longer visible on the screen :/ --Dietmar ---------------------------------------------------------------------- winni · 2021-09-09 20:40 Hi! Whatever you compute with the progressbar ... Place the ProgressBar to your  needs. Use the poroperty anchor in the OI: Anchor it to all 4 sides. If that does not help we need some code. Winni ---------------------------------------------------------------------- wp · 2021-09-09 21:16 When it's only a splash form then it should not be too difficult for you to extract it and demonstrate the issue in a simple compilable project. Too much guessing otherwise. ---------------------------------------------------------------------- dietmar · 2021-09-13 15:08 Ok, here it is... Please notice: Since I left the SQLite Init Routines in the form (because perhaps they are the reason for the problem?), you have to copy sqlite.dll into the folder to get it working. Thx, --Dietmar ---------------------------------------------------------------------- dietmar · 2021-09-20 13:45 The strange thing I just noticed is that even calculating the screen center for the splash form like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TSplashForm1.FormCreate(Sender: TObject);begin  left := (Screen.Width - self.Width) div 2;  Top :=  (Screen.Height - self.height) div 2;end; does not work --Dietmar ---------------------------------------------------------------------- winni · 2021-09-20 14:53 Quote from: dietmar on September 20, 2021, 03:45:24 pmThe strange thing I just noticed is that even calculating the screen center for the splash form like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TSplashForm1.FormCreate(Sender: TObject);begin  left := (Screen.Width - self.Width) div 2;  Top :=  (Screen.Height - self.height) div 2;end; does not work --Dietmar Hi! Set the property position in the OI to poDesigned. Otherwise the code does not work. Winni ---------------------------------------------------------------------- robert rozee · 2021-09-20 15:56 the method i use (with a regular form) is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject); begin  Form1.Left:=(Form1.Monitor.WorkAreaRect.Width-Form1.Width) div 2;    // approximate centre of screen, ignores title bar height  Form1.Top:=(Form1.Monitor.WorkAreaRect.Height-Form1.Height) div 2;   // and side border widths, but is the best we can do.  AlphaBlendValue:=0;                                                  // start up invisible, Timer1 handler  AlphaBlend:=true                                                   // fades in over approximately 225ms (comment out for testing)end;  procedure TForm1.Timer1Timer(Sender: TObject);                         // (15ms timer event)const startup:boolean=true;      holdoff:integer=-90;begin  if startup then                                                    // startup with AlphaBlend=true, slow fade in after holdoff  begin    if holdoff<0 then inc(holdoff, Timer1.Interval)                 else AlphaBlendValue:=min(AlphaBlendValue+17, 255);    if AlphaBlendValue=255 then    begin      AlphaBlend:=false;                                             // at 100% visibility turn off AlphaBlend      startup:=false                                                 // set end of startup flag, never end up here again    end  endend; as winni said, set the property position in the object inspector to poDesigned. the 90ms holdoff is to allow the form to 'snap' into position before it starts to become visible. without any holdoff, the form can be visibly seen moving on the screen. the above works in linux, as well as under winXP running in a VM. cheers, rob   :-) ---------------------------------------------------------------------- dietmar · 2021-09-21 15:12 Hm, unfortunately, "poDesigned" didn't help either --Dietmar ---------------------------------------------------------------------- dietmar · 2021-09-21 20:29 Hm, I think I just encountered a bug: When I set Position to poDesigned, all seems ok. But when I restart Lazarus afterwards, it is set back to poScreenCenter! And I assume that when compiling the project, it is already "poScreenCenter" again and therefore the code doesn't work! I searched the whole code whether there is any sign of setting it back, but I didn't found a line... Can anyone confirm this behaviour? --Dietmar ---------------------------------------------------------------------- MarkMLl · 2021-09-21 20:38 Quote from: dietmar on September 21, 2021, 10:29:02 pmHm, I think I just encountered a bug: When I set Position to poDesigned, all seems ok. But when I restart Lazarus afterwards, it is set back to poScreenCenter! And I assume that when compiling the project, it is already "poScreenCenter" again and therefore the code doesn't work! I searched the whole code whether there is any sign of setting it back, but I didn't found a line... Can anyone confirm this behaviour? Not as such, but I've been considering mentioning that my experience on Linux is that that setting is- at best- widget-set specific. It's like the old joke about social scientists' most robust prediction being "Some do, some don't". So I'm afraid that I stick by my (much) earlier comment QuoteNo, but a good place to start would probably be in the Screen and ScreenInfo objects which allow you to get at the screen/monitor dimensions (with the caveat that I've not looked at this on Windows, only Linux/Solaris). i.e. you need to dump what the various properties report in a way that doesn't itself mess up your user interface rather than trying to use them blindly. MarkMLl ---------------------------------------------------------------------- winni · 2021-09-21 22:34 Quote from: dietmar on September 21, 2021, 10:29:02 pmHm, I think I just encountered a bug: When I set Position to poDesigned, all seems ok. But when I restart Lazarus afterwards, it is set back to poScreenCenter! And I assume that when compiling the project, it is already "poScreenCenter" again and therefore the code doesn't work! I searched the whole code whether there is any sign of setting it back, but I didn't found a line... Can anyone confirm this behaviour? --Dietmar Hi! I cant confirm this. Everything works a exspected. Lin64, gtk2, fpc 3.2, Laz 2.0.12 But you can enhance you code to: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     procedure TSplashForm1.FormCreate(Sender: TObject);    begin     self.position := poDesigned; // <-- !!!!!      left := (Screen.Width - self.Width) div 2;      Top :=  (Screen.Height - self.height) div 2;    end;     Winni ---------------------------------------------------------------------- dietmar · 2021-09-24 17:24 I already tried that, but without success. I think I give up now Dietmar ---------------------------------------------------------------------- wp · 2021-09-24 22:22 This is an issue related to the different screen resolution on both systems. When I open your demo on my standard development system at 96pp everything is nicely centered. When I open it on a VM at 144ppi the form is centered too, but larger. you have an image background in the splash form which you use as a mask to get some kind of oval window. Of course, this does not scale. Since the image is in the upper left corner of the window the masked window is no longer centered. And the progressbar does no longer overlap with the image. In order to center the splash form on the high-res screen you either provide several background images depending on the actual resolutions so that they fill the window in the same way as they do at 96ppi. Or you set the TImage properties Stretch and Proportional to true to scale the image into the window. This way I was able to center the window at 144ppi. The progressbar is still off. This is due to your function MakeTransparentWindow which seems not to be compatibile with LCL scaling. When I comment out its call the the progressbar is inside the window at runtim, however at a different position. But you reposition the progressbar in the OnCreate event, and I did not check this. So, in summary: Set Image.Stretched = true and Image.Proportional = true. Look into the MakeTransparentWindow to find where it collides with LCLScaling. The easiest way, however, is to leave everything as it is now, but set the splash form's Scaled to false -- this disables LCLScaling for the splash form. The disadvantage is that the splash form appears to be smaller on a high res screen, and the progressbar appears to be thinner - but you can increase its height accordingly: pbInit.Height := Scale96ToForm(pbInit.Height) in FormOnCreate. ---------------------------------------------------------------------- dietmar · 2021-09-25 16:23 WP, you are not only "a" hero member, but MY personal hero member!! Now it finally works and I am very glad! I just made the Splash image bigger and did as you wrote in your last paragraph... Thanks a lot, also to all the others contributing here! Great work! --Diet"made my weekend"mar