gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:39:08 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com