Delphi – How to Force Scrollbar Redraw in VCL High DPI Style

delphidelphi-12-athensvclvcl-styles

Using Delphi 12.1 Athens:

  • Create a new VCL MDI application for Windows 32bit (File – New – Other, select Delphi – Windows on the left, then select MDI application, and click OK).
  • Select the "Windows 11 Polar Light" style in Project – Options – Appearance.
  • Add a panel aligned alTop
  • Add a button on the panel and name it NewBtn.
  • Add an OnClick event to each component, and add the code shown below.
  • Run the program.
  • Click the NewBtn to create one or more child forms.
  • Move a child form so that the vertical scrollbar is visible.
  • Click the panel component. It should change height, but the scrollbar will not redraw.

This has been acknowledged as a defect, but I haven't gotten any advice about a workaround. I thought I could simply resize the main window, and that works unless the window is maximized, which a lot of my users do. I tried simply calling the Resize() method, but that had no effect. I tried tracing through the VCL code, but I could not find anything that made sense to me.

object MainForm: TMainForm
  Left = 194
  Top = 111
  Caption = 'MDI Application'
  ClientHeight = 535
  ClientWidth = 610
  Color = clAppWorkSpace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -11
  Font.Name = 'Default'
  Font.Style = []
  FormStyle = fsMDIForm
  VisualManager = FormTabsBar1
  Position = poDefault
  TextHeight = 13
  object StatusBar: TStatusBar
    Left = 0
    Top = 516
    Width = 610
    Height = 19
    Margins.Left = 2
    Margins.Top = 2
    Margins.Right = 2
    Margins.Bottom = 2
    AutoHint = True
    Panels = <>
    SimplePanel = True
  end
  object FormTabsBar1: TFormTabsBar
    Left = 0
    Top = 486
    Width = 610
    Height = 30
    Align = alBottom
    ParentColor = False
    TabOptions.ShowFormIcon = True
    TabOptions.ShowFormSystemMenu = True
    TabOptions.ShowCloseButton = True
    TabOptions.ShowHintForTruncatedCaption = True
    TabMinWidth = 100
    TabMaxWidth = 250
    Visible = False
    ShowTabsMenuButton = True
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 610
    Height = 97
    Align = alTop
    Caption = 'Panel1'
    TabOrder = 2
    OnClick = Panel1Click
    object NewBtn: TButton
      Left = 20
      Top = 28
      Width = 75
      Height = 25
      Caption = 'NewBtn'
      TabOrder = 0
      OnClick = NewBtnClick
    end
  end
  object OpenDialog: TOpenDialog
    Filter = 'All files (*.*)|*.*'
    Left = 16
    Top = 272
  end
  ... Image data removed...
end
procedure TMainForm.Panel1Click(Sender: TObject);
begin
  if Panel1.Height > 100 then
    Panel1.Height := Panel1.Height - 20
  else
    Panel1.Height := Panel1.Height + 20;
end;
    
procedure TMainForm.NewBtnClick(Sender: TObject);
begin
  FileNew1Execute(nil);
end;

Best Answer

You can use this workaround inside the Panel1Click event handler and include Vcl.Themes in the uses list:

SendMessage(Handle, WM_MDICHILDMOVE, 0, 0);
Related Question