delphi - RichEdit 控件在成为其他控件的父控件时停止绘制文本

标签 delphi delphi-xe5 richedit

RichEdit 控件在成为其他控件的父控件时停止绘制文本。

这是一个功能还是一个错误? 是否可以使 RichEdit 成为其他控件的父控件?

查看下一个应用:

-- Form1.dfm ---

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 282
  ClientWidth = 418
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 24
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object RichEdit1: TRichEdit
    Left = 16
    Top = 72
    Width = 145
    Height = 105
    Font.Charset = RUSSIAN_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    Lines.Strings = (
      'RichEdit1')
    ParentFont = False
    TabOrder = 1
  end
end

-- Form1.dfm ---

--- Unit1.pas ---

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;

type
  TForm3 = class(TForm)
    Button1: TButton;
    RichEdit1: TRichEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
  Button1.Parent := RichEdit1;
  RichEdit1.Invalidate;
end;

end.

--- Unit1.pas ---

在Delphi XE5 + Win 7下测试。

我想创建带有这样的编辑按钮的 RichEdit

enter image description here

这是我想要得到的结果 - 带下拉编辑器的 RichEdit:

enter image description here

最佳答案

使用插入器类来处理 WM_PAINT 消息,如下所示:

type
  TRichEdit = class(Vcl.ComCtrls.TRichEdit)
  protected
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  end;

procedure TRichEdit.WMPaint(var Message: TWMPaint);
begin
  DefaultHandler(Message);
end;

出于时间迷雾中的原因,TCustomRichEditWM_PAINT 进行了一些特殊处理,这些处理仅是原始版本的 Rich Edit DLL 实际上需要的。此外,当另一个控件是丰富编辑的父级时,这种特殊处理会破坏正常的绘制。因此,解决该问题需要重新建立标准 VCL/Windows 绘制处理,这就是上面代码的作用。

也就是说,我怀疑在丰富的编辑中嵌套按钮是否真的是您想要的 - 例如,文本不会环绕它。

关于delphi - RichEdit 控件在成为其他控件的父控件时停止绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20590915/

相关文章:

c++ - 如何消除 RICHEDIT 控件的 MessageBeep?

delphi - 发送打印机特定命令

delphi - Delphi中的目录路径操作?

delphi - 如何在 Firemonkey 中设计时设计 TFrame 样式

string - 为什么我无法在 RichEdit 控件 (Delphi) 中插入逗号加空格

c++ - Rich Edit Control 更改 DialogBox 返回值行为?

Delphi 6 不触发断点

c# - RAD 编程语言编写一个 windows 应用程序来显示文本、播放音频文件和显示弹出气球

android - 德尔福XE5安卓: how to make each listview item have its own template?

delphi - 如何调整为 WINx86 编写的代码以编译为 WINx64