首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

RichTextBox怎么获取鼠标所在位置

2011-12-13 
RichTextBox怎样获取鼠标所在位置目的:用 GetcharIndexformPosition(point)到获取鼠标位置的字符长度但是

RichTextBox怎样获取鼠标所在位置
目的:用 GetcharIndexformPosition(point)到获取鼠标位置的字符长度
但是不知道 point怎么去获取

[解决办法]
不好意思,上面那个只能显示选定的字符串的最后一个字符是框内全部字符的第几个


下面这个能显示出选择了多少个字符



VB.NET code
Public Class Form1    Dim pt As Point    Dim ptB As Point    Dim b As Boolean    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        b = False    End Sub    Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDown        If b <> True Then            ptB.X = e.X            ptB.Y = e.Y        End If        b = True    End Sub    Private Sub RichTextBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseMove        Dim i As Integer        Dim j As Integer        If b Then            pt.X = e.X            pt.Y = e.Y            j = RichTextBox1.GetCharIndexFromPosition(ptB)            i = RichTextBox1.GetCharIndexFromPosition(pt)            Textbox1.Text = Math.Abs(i - j) '文本框内现实的数值就是个数        End If    End Sub    Private Sub RichTextBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseUp        b = False    End SubEnd Class 

热点排行