Word 文書と同様に、RichTextbox に入力されたテキストを正当化するアプリケーションを開発しています。
このリンクのコードを確認しました
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/455a6427-a3a2-4215-89a3-557114dbcddd
誰でもVBコードでより簡単なソリューションを持っていますか?
ありがとう
Word 文書と同様に、RichTextbox に入力されたテキストを正当化するアプリケーションを開発しています。
このリンクのコードを確認しました
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/455a6427-a3a2-4215-89a3-557114dbcddd
誰でもVBコードでより簡単なソリューションを持っていますか?
ありがとう
それを行うための簡単な VB コードを見つけましたが、問題なく動作します。ここにリンクがあります。
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/25045a28-b8c9-4146-9820-1231a58c5925/
リンクを紛失した場合に備えて、コードも配置しています。
' Constants and structures from richedit.h
Const MAX_TAB_STOPS = 32 ' expanded individually
Const PFA_JUSTIFY = 4 ' Left = 1, Center = 2, Right = 3
Const CBSIZE = 188 ' Size of PARAFORMAT2 structure
Const PFM_ALIGNMENT = &H8
Const WM_USER = &H400
Const EM_DISPLAYBAND = WM_USER + 51
Const EM_FORMATRANGE = WM_USER + 57
Const EM_SETPARAFORMAT = WM_USER + 71
Const EM_SETTARGETDEVICE = WM_USER + 72
<StructLayout(LayoutKind.Sequential)> _
Private Structure PARAFORMAT2
Public cbSize As Int16 'UINT cbSize;
Public dwMask As Int32 'DWORD dwMask;
Public wNumbering As Int16 'WORD wNumbering;
Public wEffects As Int16 'WORD wEffects;
Public dxStartIndent As Int32 'LONG dxStartIndent;
Public dxRightIndent As Int32 'LONG dxRightIndent;
Public dxOffset As Int32 'LONG dxOffset;
Public wAlignment As Int16 'WORD wAlignment;
Public cTabCount As Int16 'SHORT cTabCount;
Public rgxTabs1 As Int32 'LONG rgxTabs[MAX_TAB_STOPS];
Public rgxTabs2 As Int32
Public rgxTabs3 As Int32
Public rgxTabs4 As Int32
Public rgxTabs5 As Int32
Public rgxTabs6 As Int32
Public rgxTabs7 As Int32
Public rgxTabs8 As Int32
Public rgxTabs9 As Int32
Public rgxTabs10 As Int32
Public rgxTabs11 As Int32
Public rgxTabs12 As Int32
Public rgxTabs13 As Int32
Public rgxTabs14 As Int32
Public rgxTabs15 As Int32
Public rgxTabs16 As Int32
Public rgxTabs17 As Int32
Public rgxTabs18 As Int32
Public rgxTabs19 As Int32
Public rgxTabs20 As Int32
Public rgxTabs21 As Int32
Public rgxTabs22 As Int32
Public rgxTabs23 As Int32
Public rgxTabs24 As Int32
Public rgxTabs25 As Int32
Public rgxTabs26 As Int32
Public rgxTabs27 As Int32
Public rgxTabs28 As Int32
Public rgxTabs29 As Int32
Public rgxTabs30 As Int32
Public rgxTabs31 As Int32
Public rgxTabs32 As Int32
Public dySpaceBefore As Int32 'LONG dySpaceBefore;
Public dySpaceAfter As Int32 'LONG dySpaceAfter;
Public dyLineSpacing As Int32 'LONG dyLineSpacing;
Public sStyle As Int16 'SHORT sStyle;
Public bLineSpacingRule As Byte 'BYTE bLineSpacingRule;
Public bOutlineLevel As Byte 'BYTE bOutlineLevel;
Public wShadingWeight As Int16 'WORD wShadingWeight;
Public wShadingStyle As Int16 'WORD wShadingStyle;
Public wNumberingStart As Int16 'WORD wNumberingStart;
Public wNumberingStyle As Int16 'WORD wNumberingStyle;
Public wNumberingTab As Int16 'WORD wNumberingTab;
Public wBorderSpace As Int16 'WORD wBorderSpace;
Public wBorderwidth As Int16 'WORD wBorderWidth;
Public wBorders As Int16 'WORD wBorders;
End Structure
<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, _
ByVal msg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As IntPtr) As Int32
End Function
フォーム デザイナーのコードをここに入力
Private Sub btnSetAlignment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetAlignment.Click
Dim pf2 As PARAFORMAT2
rtb.SelectAll()
pf2.cbSize = CBSIZE
pf2.dwMask = pf2.dwMask Or PFM_ALIGNMENT
pf2.wAlignment = PFA_JUSTIFY
' Allocate memory for the PARAFORMAT2 struct and
' copy the contents of the struct to this memory
Dim lParam As IntPtr
lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(pf2))
Marshal.StructureToPtr(pf2, lParam, False)
Dim iRet As Integer
iRet = SendMessage(rtb.Handle(), EM_SETPARAFORMAT, 0, lParam)
' Free allocated memory
Marshal.FreeCoTaskMem(lParam)
End Sub
次のようなものを試してください
rtbox.SelectionStart =0'rtboxはリッチテキストボックスの名前です
rtbox.SelectionLength=rtbox.Text.Length
rtbox.SelectionAlignment = TextAlignment.Justify
'その他のテキスト配置の場合
'rtbox.SelectionAlignment= TextAlignment.Left'rtbox.SelectionAlignment
= TextAlignment.Right
' rtbox.SelectionAlignment = TextAlignment.Center
RichTextBoxの拡張をご覧ください。MSDN の例に似ていますが、少し単純です。