在textBox中,如何知道当前光标的位置? textBox1.SelectionStart也不知道对不对,刚学C#,这是在C#回答的第一个问题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用javascript来实现,代码如下:<html><head><title>New Page 1</title><script language="javascript">function CheckCur(Item){ var Text = Item.value; var currentRange=document.selection.createRange(); document.all("B1").value = Text.length; document.all("B2").value = getCursorPos(Item);}function getCursorPos(obj) { obj.focus(); var currentRange=document.selection.createRange(); var workRange=currentRange.duplicate(); obj.select(); var allRange=document.selection.createRange(); var pos=0; while(workRange.compareEndPoints("StartToStart",allRange)>0) { workRange.moveStart("character",-1); pos++; } currentRange.select(); return pos;}</script></head><body><form method="POST" action="--WEBBOT-SELF--"> <p><input type="text" name="T1" onkeyup="javascript:CheckCur(this)" size="20"> <input type="button" value="aaa" name="B1"> <input type="button" value="bbb" name="B2"></p></form></body></html> Sorry,没看仔细,我还以为在WebForm中呢,在WinForm中如一楼的做法即可:textBox1.SelectionStart.ToString(); C#添加调制解调器并进行自动进行拨号和断线 【初学者求教】SQL语句 切换选项卡的问题 MessageBox类的Show方法第一个参数的问题,谢谢 关于数组的问题! 视频剪切 请问SortedList如何按新增顺序排序,而不是按键名排序 类里面的那个internal和private有什么区别? 请各位指教:为什么这个函数接收不到UDP报文? 有没有办法让远程机器弹出一个对话框? dataGrid的问题 为什么什么都 不显示了!
<html>
<head>
<title>New Page 1</title>
<script language="javascript">
function CheckCur(Item)
{
var Text = Item.value;
var currentRange=document.selection.createRange();
document.all("B1").value = Text.length;
document.all("B2").value = getCursorPos(Item);
}function getCursorPos(obj)
{
obj.focus();
var currentRange=document.selection.createRange();
var workRange=currentRange.duplicate();
obj.select();
var allRange=document.selection.createRange();
var pos=0;
while(workRange.compareEndPoints("StartToStart",allRange)>0)
{
workRange.moveStart("character",-1);
pos++;
}
currentRange.select();
return pos;
}</script>
</head><body><form method="POST" action="--WEBBOT-SELF--">
<p><input type="text" name="T1" onkeyup="javascript:CheckCur(this)" size="20">
<input type="button" value="aaa" name="B1">
<input type="button" value="bbb" name="B2"></p>
</form></body></html>
textBox1.SelectionStart.ToString();