windows - 如何在Windows主题下使用Delphi显示一个 "greyed-out"只读复选框

标签 windows delphi themes readonly tcheckbox

我希望只读复选框变灰,但在 Windows(XP 及更高版本)下显示其选中/未选中状态,但我遇到了一些问题。

注意 - 关于“只读”:似乎 Delphi 的 TCheckBox 甚至没有只读选项,这是通过将它放在 TPanel 上并禁用它来“伪造”的......但是问题仍然有效,如何实现一个灰色的只读复选框,或者一个显示其状态的非事件复选框。

禁用的复选框显示为灰色,但不会显示选中或未选中状态。只读复选框可以,但是当 Windows 为它们设置主题时,它们看起来就像普通的可编辑复选框。只读框不能更改其值,但看起来可以。

在关闭主题的 XP 中(即在经典模式下),它可以正常工作。

Not Acceptable 解决方案包括: - 手动使文本变灰并显示复选框状态的图像。 - 禁用复选框上的主题,因为没有它们的外观很难看。 - 使用自定义复选框

问题的屏幕截图 - 这是三个选中的复选框,一个已禁用,一个只读,一个正常:

enter image description here enter image description here

虽然只读和可编辑复选框看起来不同,但这只是因为第一个图像中的可编辑框具有焦点。如果只读的是有焦点的,那么它看起来是一样的,如第二张图片所示。

最佳答案

带有主题的复选框在禁用时会显示选中标记,如您在此屏幕截图中所见:

enter image description here

用于创建它的 dfm 如下所示:

object Form2: TForm2
  Left = 0
  Top = 0
  Caption = 'Form2'
  ClientHeight = 337
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object CheckBox1: TCheckBox
    Left = 8
    Top = 8
    Width = 153
    Height = 17
    Caption = 'Disabled an checked'
    Checked = True
    Enabled = False
    State = cbChecked
    TabOrder = 0
  end
  object CheckBox2: TCheckBox
    Left = 8
    Top = 31
    Width = 153
    Height = 17
    Caption = 'Enabled and checked'
    Checked = True
    State = cbChecked
    TabOrder = 1
  end
  object CheckBox3: TCheckBox
    Left = 8
    Top = 54
    Width = 153
    Height = 17
    Caption = 'Disabled an un-checked'
    Enabled = False
    TabOrder = 2
  end
  object CheckBox4: TCheckBox
    Left = 8
    Top = 77
    Width = 153
    Height = 17
    Caption = 'Enabled and un-checked'
    TabOrder = 3
  end
end

关于windows - 如何在Windows主题下使用Delphi显示一个 "greyed-out"只读复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5240555/

相关文章:

.net - 将字符串从 Delphi dll 传递到 .net

sql - 按包含数字和字母的字段排序

c# - 如何设置机箱风扇速度

c - 反编译一个c dll以使用pinvoke

Delphi SysUtils.Supports 意外返回 true

python - PyQt:如何找到适用于 Ubuntu Unity 的菜单文本颜色?

wordpress - 如何通过 https 更改主题图片?

drupal - 在 Drupal 7 中为表单调用自定义 Theme() 函数

windows - 在 powershell 中生成 RSA key 对

windows - 在 DLL 中,函数表的结构是怎样的?