| 发表于:2007-03-02 17:50:476楼 得分:4 |
option explicit private declare function sendmessage lib "user32 " alias "sendmessagea " (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long const em_getsel = &hb0 const em_linefromchar = &hc9 const em_lineindex = &hbb public sub getpos(byval hwnd5 as long, lineno as long, colno as long) dim i as long, j as long dim lparam as long, wparam as long dim k as long i = sendmessage(hwnd5, em_getsel, wparam, lparam) j = i / 2 ^ 16 '取得目前光标所在位置前有多少个byte lineno = sendmessage(hwnd5, em_linefromchar, j, 0) '取得光标前面有多少行 lineno = lineno + 1 k = sendmessage(hwnd5, em_lineindex, -1, 0) '取得目前光标所在行前面有多少个byte colno = j - k + 1 end sub private sub text1_keydown(keycode as integer, shift as integer) if keycode = vbkeyreturn then dim i as long, j as long getpos text1.hwnd, i, j text1 = left(text1, (i - 1) * text1.maxlength + j - 1) + " " + right(text1, len(text1) - (i - 1) * text1.maxlength - j + 1) text1.selstart = (i - 1) * text1.maxlength + j - 1 end if end sub 这个只对英文支持,由于中文占两个字节,所以你要改一下getpos函数,自己做吧 | | |
|