请教richedit控件问题!

byrdhcl 2008-06-12 09:47:28
richedit控件有个功能,就是按下鼠标左键,同时转动鼠标中轮,richedit中所有的字体,可以随着中轮的转动,变大或者变小。我想用其他方式实现这一功能(例如:按钮)。
我试着直接改变richedit中字体字号的方式来实现,如果richedit中的字体是一个字号(同样大小),这一功能可以实现,但是如果richedit中有不同字号的字体,这一功能却无法实现。

请高手指点!
...全文
52 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
byrdhcl 2008-06-12
也可以说是如何实现richedit的zoom功能
回复
喝口水 2008-06-12
没弄过,路过
回复
byrdhcl 2008-06-12
将源码贴出供大家研究(控件自己添加,4个按钮、1个richedit):

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;

type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
function GetZoom: Integer;
procedure SetZoom(Value: Integer);
property Zoom: Integer read GetZoom write SetZoom;

public
{ Public declarations }
end;
const
EM_GETZOOM = (WM_USER + 224);
EM_SETZOOM = (WM_USER + 225);
var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Zoom := 100;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Form1.Zoom := 200;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Form1.Zoom := 300;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Form1.Zoom := 400;
end;

function TForm1.GetZoom: Integer; // Added by J.G. Boerema
var wp,lp: Integer;
begin
Result := 100;
SendMessage(Richedit1.Handle, EM_GETZOOM, Integer(@wp), Integer(@lp));
if (lp > 0) then Result := MulDiv(100,wp,lp);
end;

procedure TForm1.SetZoom(Value: Integer);
begin
if Value = 0 then
SendMessage(Richedit1.Handle, EM_SETZOOM, 0, 0)
else
SendMessage(Richedit1.Handle, EM_SETZOOM, Value, 100);
end;



end.


回复
byrdhcl 2008-06-12
呵呵,没有人解决。自己解决了!
回复
相关推荐
发帖
Delphi
创建于2007-08-02

4923

社区成员

Delphi 开发及应用
申请成为版主
帖子事件
创建了帖子
2008-06-12 09:47
社区公告
暂无公告