首页  编辑  

TextBox取得自动换行后的字符串数组

Tags: /C#/界面处理/TextBox_RichEdit/   Date Created:

using System . Runtime . InteropServices;

[ DllImport ( "User32.dll" )]

static extern int SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam);

[ DllImport ( "User32.dll" , EntryPoint = "SendMessage" )]

static extern int SendMessageBuffer( IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);

private const int EM_GETLINECOUNT = 0x00BA ;

private const int EM_GETLINE = 0x00C4 ;

private void button1_Click( object sender , EventArgs e)

{

    StringBuilder vBuffer = new StringBuilder ( "\0xff\0x00" , 256 );

   

    int vCount = SendMessage(textBox1 . Handle, EM_GETLINECOUNT, 0 , 0 );

    for ( int i = 0 ; i < vCount; i ++ )

   {

       SendMessageBuffer(textBox1 . Handle, EM_GETLINE, i, vBuffer);

       richTextBox1 . Text += vBuffer + "\r\n" ;

   }

}