■8671 / ) |
RichTextBoxの行間を詰める方法 |
□投稿者/ tk (13回)-(2007/10/05(Fri) 19:42:41)
|
分類:[.NET 全般]
いつもお世話になっております。
調べに調べたのですが、ここを最終手段として質問させてください。
表題の通り、RichTextBoxの行間を詰める方法ですが、 どうやらPARAFORMAT2構造体をSendMessageするというのが妥当みたいです。 ただこれを実現しているサンプルがなかったので、この方法自体有用なのかは わかりません。
とりあえずコードを既述します。
まず、DLLに送るための構造体としてこのように宣言します。 [StructLayout(LayoutKind.Sequential)] public struct PARAFORMAT2 { public uint cbSize; public uint dwMask; public ushort wNumbering; public ushort wEffects; public int dxStartIndent; public int dxRightIndent; public int dxOffset; public ushort wAlignment; public short cTabCount; [MarshalAs(UnmanagedType.I4, SizeConst = 32)] //←ここの書き方怪しい・・・ public int rgxTabs; public int dySpaceBefore; public int dySpaceAfter; public int dyLineSpacing; public short sStyle; public byte bLineSpacingRule; public byte bOutlineLevel; public ushort wShadingWeight; public ushort wShadingStyle; public ushort wNumberingStart; public ushort wNumberingStyle; public ushort wNumberingTab; public ushort wBorderSpace; public ushort wBorderWidth; public ushort wBorders; }
そしてRichTextBoxがnewされた後くらいに const int EM_SETPARAFORMAT = 0x0447; const uint PFM_LINESPACING = 0x00000100; //DLLのメモリ確保して IntPtr p = Marshal.AllocCoTaskMem(Marshal.SizeOf(new ChildRichEdit.PARAFORMAT2())); //設定必要だからマネージに戻して ChildRichEdit.PARAFORMAT2 cf = (ChildRichEdit.PARAFORMAT2)Marshal.PtrToStructure(p, typeof(ChildRichEdit.PARAFORMAT2)); //適当な値をセットして cf.cbSize = (uint)Marshal.SizeOf(new ChildRichEdit.CHARFORMAT()); cf.dwMask |= PFM_LINESPACING; cf.bLineSpacingRule = 4; cf.dyLineSpacing = 40; //アンマネージに戻して Marshal.StructureToPtr(cf, p, true);
//SendとFree int ret = SendMessage(this.richTextBox1.Handle, EM_SETPARAFORMAT, 0, p); Marshal.FreeCoTaskMem(p);
以上ですが、現状SendMessageの戻り値がエラーの0なので間違っていることは確定です。
私が知りたいのは、 ・そもそも行間を詰めることはできるのか ・上記の方法は正しいのか の2点です。
因みに調べていくうちにEM_SETCHARFORMATをSendMessageする方法も試したのですが、 http://yokohama.cool.ne.jp/chokuto/urawaza/struct/CHARFORMAT.html こちらは行間とは違うようでした。(SendMessage自体は成功しました)
本当に恐縮ではありますが、どなたかご教授頂けないでしょうか。
|
|