【问题标题】:How to Fix the TComboBox Ctl3D Property Bug?如何修复 TComboBox Ctl3D 属性错误?
【发布时间】:2012-10-08 20:03:35
【问题描述】:

这是来自TForm 的图片,其中我在顶部有一个TEdit,在下方有一个TComboBox

如您所见,TEdit 没有 Windows 控件默认主题的经典 3D 边框。那是因为我将该组件的Ctl3D property 设置为False。然后您会看到 TComboBox 具有正常的 3D 边框,但在这种情况下,我还将该组件的 Ctl3D property 设置为 False,但它仍然显示 3D 边框。

这似乎是开发级别的 Delphi 错误。我该如何在代码中解决这个问题?


在测试 RRUZ 答案后,BevelKind=bkFlat,来了:

我不知道为什么它如此不同......而且很奇怪。 :-/

【问题讨论】:

  • 其他带来 ComboBox 变化的组件包可以纠正这个问题,但是我们不能像那些 TEdits 那样将边框颜色设置为黑色
  • 尝试将 ComboBox 的 BevelKind 属性设置为 bkFlat

标签: delphi interface combobox delphi-2006


【解决方案1】:

您可以移除 3D 边框,将TComboBoxBevelKind 属性设置为bkFlat

【讨论】:

  • 我将结果放在问题中。我不知道为什么,但它离你的 Delphi 很远。 :(
【解决方案2】:

我找到了:

我们必须设置:

BevelInnerbvNone ;

BevelKindbkFlat ;

BevelOuterbvSpace

【讨论】:

    【解决方案3】:

    这是支持BidiMode并调整大小的最佳方式;并且可以用客户端颜色填充边框:

    TTestComboBox=class(TComboBox)
    protected
      procedure WMPaint(var Msg: TMessage); message WM_Paint;
    End;
    
    Procedure TTestComboBox.WMPaint(var Msg: TMessage);
    var MCanvas: TControlCanvas;
        R: TRect;
    Begin
      inherited;
      MCanvas:=TControlCanvas.Create;
      Try
        MCanvas.Control:=Self;
        With MCanvas do begin
          R:=ClientRect;
          Brush.Style:= bsClear;
          Pen.Color:= Color;
          Pen.Width:= 3;
          if BiDiMode in [bdRightToLeft, bdRightToLeftNoAlign] then begin
            if Style = csSimple then                   //remove border and space
              Rectangle(1, 1, R.Width - 1, R.Height-1) else Rectangle(-1, 1, R.Width, R.Height-1);
            if Style in [csDropDown, csOwnerDrawFixed, csOwnerDrawVariable] then begin
              Pen.Width:= 5;                           //remove space btw editor and button
              MoveTo(18, 0);
              LineTo(18, R.Height-1);
            end;
          end else begin
            if Style = csSimple then
              Rectangle(1, 1, r.Width - 1, R.Height-1) else Rectangle(1, 1, r.Width + 1, R.Height-1);
            if Style in [csDropDown, csOwnerDrawFixed, csOwnerDrawVariable] then begin
              Pen.Width:= 5;
              MoveTo(R.Width - 18, 0);
              LineTo(R.Width - 18, R.Height-1);
            end;
          end;
        end;
      finally
        MCanvas.Free;
      End;
    End;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多