首页  编辑  

TextBox取得光标停留的行号

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

using System . Runtime . InteropServices;

[ DllImport ( "User32.DLL" )]

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

private const int EM_LINEFROMCHAR = 0xC9 ;

private const int EM_LINEINDEX = 0xBB ;

private void button6_Click( object sender, EventArgs e)

{

    int Y = SendMessage(textBox1 . Handle, EM_LINEFROMCHAR, textBox1 . SelectionStart, 0 );

    int X = SendMessage(textBox1 . Handle, EM_LINEINDEX, Y, 0 ); //

}

// or

int Y = textBox1 . GetLineFromCharIndex(textBox1 . SelectionStart);

int X = textBox1 . GetFirstCharIndexFromLine(Y);