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

要做记事簿求解

2012-08-07 
要做记事本求解求一个代码就是 输入行数然后光标能够自动转到那一行的最前面,找了很多都没有找到。就是系统

要做记事本求解
求一个代码就是 输入行数然后光标能够自动转到那一行的最前面,找了很多都没有找到。
就是系统自带的那种“转到”功能。

还有一个代码是记事本里的转到代码,有什么向上向下还有区分大小写的,急需阿><!

正确了给大大的分数阿

[解决办法]
下面的代码将光标首先定位到开始,然后一行一行的定位到哪第五行的开始,因为textbox中可能不是硬回车。所以注释的代码不能用,如果每行都是硬回车的话就可以。
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "rdasgfdshshslhafdjklshjaghraifgupasgvnfavjncxz,.;nczm,n.xcz.,vn;zgh;zxvjhn;afsgjnf;asgjn;afghjdf;hgdf.;abnbvdfn.;asghdjajcxbn.zm,ns.zghdf;gh.f;z"
TextBox1.Text = TextBox1.Text & TextBox1.Text & TextBox1.Text & TextBox1.Text & TextBox1.Text
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.SelectionStart = 0
TextBox1.SelectionLength = 0
TextBox1.Select()
'Dim nxt As Integer = TextBox1.Text.IndexOf(vbCrLf, TextBox1.SelectionStart)
'If nxt < 0 Then
' '--- Not found, start adding empty lines
' TextBox1.Text += vbCrLf
' TextBox1.SelectionStart = TextBox1.Text.Length
'Else
' '--- Got it, move to next line
' TextBox1.SelectionStart = nxt + vbCrLf.Length
'End If
TextBox1.Focus()
SendKeys.Send("{DOWN}")

SendKeys.Send("{DOWN}")
SendKeys.Send("{DOWN}")
SendKeys.Send("{DOWN}")
End Sub
End Class

[解决办法]
Public Class Form1
Dim zhaodao As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '从开始进行搜索

TextBox1.Focus()
zhaodao = InStr(TextBox1.Text, TextBox2.Text)
If zhaodao Then
TextBox1.SelectionStart = zhaodao - 1
TextBox1.SelectionLength = Len(TextBox2.Text)

End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '搜索下一个

TextBox1.Focus()
zhaodao = InStr(zhaodao + Len(TextBox2.Text), TextBox1.Text, TextBox2.Text, CompareMethod.Text) '文本方法比较
'zhaodao = InStr(zhaodao+Len(TextBox2.Text), TextBox1.Text, TextBox2.Text, CompareMethod.Binary) '二进制方法比较
If zhaodao Then
TextBox1.SelectionStart = zhaodao - 1
TextBox1.SelectionLength = Len(TextBox2.Text)

End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "qwerqwerQWERqwerqwerQWERqwerqwerQWERqwerqwerQWERqwerqwerQWERqwerqwerQWERqwerqwerQWERqwerqwerQWER"
TextBox2.Text = "qwe"
End Sub
End Class

热点排行