【问题标题】:set the background color of a themed StatusBar component设置主题状态栏组件的背景颜色
【发布时间】:2011-05-16 18:11:42
【问题描述】:

如何设置主题TStatusBar 组件的背景颜色?当我设置颜色属性时,它仅在 Enabled runtime themes 被禁用时才有效。

提前致谢。

【问题讨论】:

  • 主题的目的:确保一致的颜色和字体方案。因此,当主题启用时,大多数(如果不是全部)颜色和字体属性的更改都会被忽略,这确实是意料之中的。
  • 我想改变颜色,因为是为了向用户显示警报消息并引起他们的注意。
  • 主题是允许用户控制颜色。你应该与他们合作,而不是试图对抗他们。

标签: delphi delphi-2007


【解决方案1】:

不确定这是否正是您需要的,但您可以简单地禁用特定控件的主题绘画,在本例中是您的状态栏,如下所示:

Uses
  uxTheme;

SetWindowTheme(StatusBar1.Handle, '', '');

【讨论】:

    【解决方案2】:

    您可以编写自己的 OwnerDraw-Event 并使用自己的颜色绘制 StatusBar(准确地说:上面的每个 Panel!):

    procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
      Panel: TStatusPanel; const Rect: TRect);
    begin
      with StatusBar.Canvas do begin
        Brush.Color := clRed;
        FillRect(Rect);
        TextOut(Rect.Left, Rect.Top, 'Panel '+IntToStr(Panel.Index));
      end;
    end;
    

    但在使用主题时,无法在 Object-Inspector 中更改颜色。

    【讨论】:

    • 只是一些提示: 1)没有必要在你的代码中指定statusbar1,因为事件已经通过了TStatusBar。 2) 为此,您需要将面板的样式设置为 psOwnerDraw。 3) 我不是 constuct 的忠实粉丝。
    • 1) 好的。已编辑。 2) 是的。 3) 这主要是口味问题,不是吗?
    • with 被认为是有害的,请参阅:stackoverflow.com/questions/71419/whats-wrong-with-delphis-with
    猜你喜欢
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多