当放入StatusBar时,Delphi Combobox会降低Win7中的行为

时间:2013-10-28 17:42:40

标签: delphi windows-7 combobox delphi-xe

我有一个已放置组合框的Delphi应用程序。最近在迁移到Win 7之后,通知组合框下拉的行为很有趣。它在XP中的预期工作正常,其中组合框下拉从状态栏rectange。但在Windows 7中,Combobox下拉区域显示在顶部屏幕上,闪烁。必须保持鼠标按钮以保持显示,但这不允许选择任何项目。

不确定是否有其他人经历过同样的事情?请告知在Win 7中需要进行哪些特殊处理才能使组合框下拉到状态栏内时完美地工作。

PS:放在表单上的Combobox在Win7中正常运行。仅当组合框放置在状态栏内时才会显示上述行为。

感谢您的意见和/或建议。

感谢。

演示代码:

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 个答案:

答案 0 :(得分:0)

我认为你需要的是一个塞子,以便事件处理程序知道何时停止绘制到画布或不执行。

或者你可以尝试这个,它适用于我(在Windows 8上的delphi XE,将组合框置于状态栏中,并将其行为更改为“放下”项目列表)。

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;
相关问题