调用API库:
[DllImport("user32.dll", EntryPoint = "SendMessageA")]private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam);[DllImport("user32 ")]private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
在函数里调用API函数即可:
int EM_LINEINDEX = 0xBB;int EM_LINEFROMCHAR = 0xC9;int EM_GETSEL = 0xB0;int EM_GETLINE = 0xC4;//通过API完成很简单的 //通过向文本框传递EM_LINEFROMCHAR消息可以得到光标所在的行数 int Row = (int)SendMessage(txtSendData.Handle, EM_LINEFROMCHAR, -1, 0);//通过向文本框传递EM_GETSEL消息可以得到编辑控件中一段选定内容的起点与终点字符的个数 int s = (int)SendMessage(textBox1.Handle, EM_GETSEL, 0, 0);//通过向文本框传递EM_GETSEL消息可以得到每一行的第一个字符在全文中的字符序号 int li = (int)SendMessage(textBox1.Handle, EM_LINEINDEX, -1, 0);