Win32 APIにはEM_FMTLINES
メッセージがあります。このメッセージをTextBox
制御に送信した場合、そのText
プロパティには、ソフト改行文字が含まれます。ソフト改行文字はCrCrLf
文字の組み合わせであり、ワードラッピングのために行が壊れている場所をマークするために使用されます。
Module TextBoxExtension
Private Const EM_FMTLINES As UInteger = &HC8
<DllImport("user32.dll", CharSet:=CharSet.Auto)>
Private Function SendMessage(hWnd As IntPtr, Msg As UInteger, wParam As Integer, lParam As IntPtr) As IntPtr
End Function
<Extension()>
Public Function GetWrappedText(ByVal textBox As TextBox) As String
Dim handle = textBox.Handle
SendMessage(handle, EM_FMTLINES, 1, IntPtr.Zero)
GetWrappedText = textBox.Text
SendMessage(handle, EM_FMTLINES, 0, IntPtr.Zero)
End Function
End Module
MemoEdit
クラスはTextBoxMaskBox
クラスのインスタンスを保持するボックスである:ここ
は、単純な拡張モジュールの一例です。 TextBoxMaskBox
クラスはSystem.Windows.Forms.TextBox
クラスから継承されています。あなたはMemoEdit.MaskBox
プロパティからそれを得ることができます。
Dim text = MemoEdit1.MaskBox.GetWrappedText
そして今、あなたはString.Split
方法使用して行を取得することができます:
Dim lines = text.Split({vbCr & vbCrLf, vbCrLf, vbLf}, StringSplitOptions.None)
を