0
votes

I have a Delphi application which has placed combobox. Recently after migrating to Win 7, notice behavior of combobox drop down is funny. It works fine as expected in XP where combobox dropdown from status bar rectange. But in Windows 7, Combobox drop down area is shown at top screen with flickering. One will have to keep the mouse button down to keep that shown, but that doesn't allow selecting any item.

Not sure if any other has experienced the same? Please advise what special handling need to be done in Win 7 for the combobox drop down to work perfectly when placed inside Status bar.

PS: Combobox placed on form behaves normally in Win7. Above cited behavior is only shown when combobox is placed inside status bar.

Appreciate your comments and/or suggestions.

Thanks.

Demo Code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    StatusBar1: TStatusBar;
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
      const Rect: TRect);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  Style, idx: Integer;
begin
    StatusBar1.Panels[0].Style := psOwnerDraw;
    ComboBox1.Parent := StatusBar1;
    Style := GetWindowLong(ComboBox1.Handle, GWL_EXSTYLE);
    Style := Style - WS_EX_STATICEDGE;
    SetWindowLong(ComboBox1.Handle, GWL_EXSTYLE, Style);
    for idx := 1 to 20 do
       ComboBox1.Items.Add(Format('Test Item %d',[idx]));
end;

procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
  const Rect: TRect);
begin
  if Panel = StatusBar1.Panels[0] then
    with ComboBox1 do
    begin
      Top := Rect.Top;
      Left := Rect.Left;
      Width := Rect.Right - Rect.Left - 5;
      Height := Rect.Bottom - Rect.Top - 10;
    end
end;

end.
1
Which Delphi version?David Heffernan
Thanks David. It is Delphi XE - Update 1user2929116
I cannot duplicate your problem (XE update1, W764-SP1). The only anomaly I observed was the difficulty convincing the IDE to let the statusbar parent the combobox.Sertac Akyuz
Thanks Sertac. I created a demo App on W7 Pro 64bit-SP1. And it is showing the same behavior as cited above. Comments area is not allowing me to post all of the code. So updating my question with demo code.user2929116
@user - My suggestion is, don't try to modify the position of controls in a paint cycle. Position the combobox elsewhen. You can apply the initial position while you're parenting the combobox. If the box's position also depend on the statusbar's size, then you'd probably like to use the OnResize event of the statusbar.Sertac Akyuz

1 Answers

0
votes

I think what you need is a stopper, so that the event handler knows when to stop drawing to the canvass or not to execute.

Or you can try this, it worked for me (delphi XE on Windows 8, to place combobox in statusbar, and change its behaviour to "drop up" items list).

procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
begin
  if Panel = StatusBar1.Panels[0] then
    with ComboBox1 do
    begin
      if Top = Rect.Top then Exit; //add this 
      Top := Rect.Top;
      Left := Rect.Left;
      Width := Rect.Right - Rect.Left - 5;
      Height := Rect.Bottom - Rect.Top - 10;
    end
end;