[delphi-users:2919] TRichEditで半角文字入力時に Arial フォントに切り替わる

248 views
Skip to first unread message

snail3

unread,
Dec 11, 2012, 11:42:20 AM12/11/12
to delphi...@freeml.com
いつもお世話になっています。

XE2 で TRichEditを使用すると半角文字入力時、勝手に Arial フォントに
切り替わるため入力した文字が汚く困っています。
Web検索したところずばり

VB.NET】リッチテキストのフォントが勝手に変更されるのを抑制する
http://blog.livedoor.jp/akf0/archives/51460770.html

というページを見つけたのですが、どのようにコーディングして良いのか
わかりません。親切な方お助け下さい。

--
takashi <taka...@csjpn.com>


MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
クリスマスアイテム追加!アバターをつくってMLメンバーに自慢しよう
http://ad.freeml.com/cgi-bin/sa.cgi?id=jpLkw
------------------------------------------------------[freeml byGMO]--

DEKO

unread,
Dec 11, 2012, 1:36:43 PM12/11/12
to delphi...@freeml.com
こんにちは。

昔、公式フォーラムでやり方書いたんですけどね...消えちゃいました。
https://www.google.co.jp/search?q=Delphi+RichEdit+DualFont&ie=utf-8&oe=utf-8&aq=t&hl=ja

1.CreateParams をオーバーライドして、旧 RICHEDIT を呼び出すようにした。
2.クラスヘルパで Dual-Font の有効/無効を実装した。
 (Dual-Font を無効にした)

なんて事をやった気がします。当時の記憶を頼りにクラスヘルパを再現してみました。

--------------------------------------------------------------------------------
unit uRichEditHelper;

interface

uses
Windows, Messages, ComCtrls;

type
TRichEditHelper = class helper for TRichEdit
private
function GetLangOptions: Word;
procedure SetLangOptions(const Value: Word);
published
property LangOptions: Word read GetLangOptions write SetLangOptions;
end;

const
IMF_AUTOKEYBOARD = $0001;
IMF_FORCENONE = $0001;
IMF_AUTOFONT = $0002;
IMF_FORCEENABLE = $0002;
IMF_IMECANCELCOMPLETE = $0004;
IMF_FORCEDISABLE = $0004;
IMF_CLOSESTATUSWINDOW = $0008;
IMF_IMEALWAYSSENDNOTIFY = $0008;
IMF_AUTOFONTSIZEADJUST = $0010;
IMF_UIFONTS = $0020;
IMF_VERTICAL = $0020;
IMF_FORCEACTIVE = $0040;
IMF_DUALFONT = $0080;
IMF_FORCEINACTIVE = $0080;
IMF_FORCEREMEMBER = $0100;
IMF_MULTIPLEEDIT = $0400;

implementation

{ TRichEditHelper }

function TRichEditHelper.GetLangOptions: Word;
const
EM_GETLANGOPTIONS = WM_USER + 121;
begin
result := SendMessage(Self.Handle, EM_GETLANGOPTIONS, 0, 0);
end;

procedure TRichEditHelper.SetLangOptions(const Value: Word);
const
EM_SETLANGOPTIONS = WM_USER + 120;
begin
SendMessage(Self.Handle, EM_SETLANGOPTIONS, 0, Value);
end;
end.
--------------------------------------------------------------------------------

この Unit を uses して、

RichEdit1.LangOptions := RichEdit1.LangOptions and (not IMF_DUALFONT);

でデュアルフォントが無効になると思います。

# 当時の実装とは異なるかもしれません。

--
by DEKO
-----------------------------
http://ht-deko.minim.ne.jp/
de...@ht-deko.minim.ne.jp
-----------------------------


MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
使い方はいろいろ♪一部のメンバーだけにMLメールを送ろう!
http://ad.freeml.com/cgi-bin/sa.cgi?id=jpL3S
------------------------------------------------------[freeml byGMO]--

snail3

unread,
Dec 11, 2012, 6:40:46 PM12/11/12
to delphi...@freeml.com
ありがとうございます。みごとにフォントが直りました。

まさかこんなに短時間でお返事をいただけると思っていなかったので
二重に感激です。
--
takashi <taka...@csjpn.com>


MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
メンバーで使える掲示板を活用しよう!
http://ad.freeml.com/cgi-bin/sa.cgi?id=jpMQL
------------------------------------------------------[freeml byGMO]--

DEKO

unread,
Dec 11, 2012, 10:53:26 PM12/11/12
to delphi...@freeml.com
すみません、ソースコード中の Word は DWORD で置換しておいて下さい。
多分、Word のままでも大丈夫だとは思いますが、念の為に。

[TRichEdit で英数字等のフォントが勝手に変わる (Delphi 2009 以降)]
http://ht-deko.minim.ne.jp/ft1212.html#121212_03

--
by DEKO
-----------------------------
http://ht-deko.minim.ne.jp/
de...@ht-deko.minim.ne.jp
-----------------------------


MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
メールだけでみんなを招待できる便利機能♪
http://ad.freeml.com/cgi-bin/sa.cgi?id=jpR2t
------------------------------------------------------[freeml byGMO]--

Reply all
Reply to author
Forward
0 new messages