您现在的位置: 雪儿网络 >> 站长学院 >> 网络编程 >> 文章正文

文章标题

如何实现在textbox中如何得知caret所在位置

『 更新时间:2007-6-26 』『 字体:变小 变大 』『 作者:北方网络 | 来源:不详 』
 

'在form中放一个textbox两个label

const em_getsel = &hb0

const em_linefromchar = &hc9

const em_lineindex = &hbb

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

public sub getcaretpos(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 '取得目前caret所在前面有多少个byte

lineno = sendmessage(hwnd5, em_linefromchar, j, 0) '取得前面有多少行

lineno = lineno + 1

k = sendmessage(hwnd5, em_lineindex, -1, 0)

'取得目前caret所在行前面有多少个byte

colno = j - k + 1

end sub

private sub form_load()

dim lineno as long, colno as long

call getcaretpos(text1.hwnd, lineno, colno)

label1.caption = lineno

label2.caption = colno

end sub

private sub text1_keyup(keycode as integer, shift as integer)

dim lineno as long, colno as long

call getcaretpos(text1.hwnd, lineno, colno)

label1.caption = lineno

label2.caption = colno

end sub

private sub text1_mousedown(button as integer, shift as integer, x as single, y as single)

dim lineno as long, colno as long

call getcaretpos(text1.hwnd, lineno, colno)

label1.caption = lineno

label2.caption = colno

end sub

【点击数:】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口

关文章

您的姓名:
评分等级:
1分 2分 3分 4分 5分
评论内容:
1、严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
2、用户需对自己在使用雪儿网络服务过程中的行为承担法律责任。
3、本站管理员有权保留或删除评论内容。
4、评论内容只代表网友个人观点,与本网站立场无关。
雪儿网络
copyright©2006-2008 xueol.com 鄂icp备06022161号
返回网站顶部