[IMG]http://img607.**************/img607/1268/adszitb.png[/IMG]
Oncelikle imlecin nerede oldugunu bulan bir fonksiyon tanimlamaliyiz. Cunku imlec mouse yardimi ile de konumlandirilabiliyor..
PHP Code:
Private Function FindCursor(ByVal textbox As System.Windows.Forms.TextBox) As Integer
Dim index As Integer = textbox.SelectionStart
Dim line As Integer = TextBox1.GetLineFromCharIndex(index)
Dim cursor As Integer = index - textbox.GetFirstCharIndexFromLine(line)
Return cursor
End Function
Bu fonksiyon bize imlecin kacinci karakterde oldugunu veriyor..
Textbox1 de Fonkiyonu kullanmak istiyorsunuz mesela
Kullanim: FindCursor(Textbox1)
Sonuc size integer olarak donecektir..
Label1.Text = FindCurcor(Textbox1).ToString
seklinde de olabilir..
Imleci buton ile sola almak icin :
PHP Code:
Dim cursor As Integer = FindCursor(TextBox1)
If cursor = 0 Then cursor = 1
TextBox1.Select(cursor - 1, 0)
TextBox1.Focus()
imlecin nerede oldugunu buluyoruz
daha sonra textbox1 de imleci bir sola Select yardimi ile aliyoruz
eger cursor 0 da ise onu 1 yapiyoruz ki Cursor - 1 hata vermesin
Imleci Buton ile sola almak icin :
PHP Code:
Dim cursor As Integer = FindCursor(TextBox1)
TextBox1.Select(cursor + 1, 0)
TextBox1.Focus()
Yine ayni sekilde cursoru bulup bir artirarak bir saga aliyoruz..
Texbox1.Select Metodu nasil kullanilir , ne ise yarar burdan bakabilirsiniz..
Tum Proje Kodlari :
PHP Code:
Public Class Form1
Private Function FindCursor(ByVal textbox As System.Windows.Forms.TextBox) As Integer
Dim index As Integer = textbox.SelectionStart
Dim line As Integer = TextBox1.GetLineFromCharIndex(index)
Dim cursor As Integer = index - textbox.GetFirstCharIndexFromLine(line)
Return cursor
End Function
Private Sub Button_Sola_Click(sender As System.Object, e As System.EventArgs) Handles Button_Sola.Click
Dim cursor As Integer = FindCursor(TextBox1)
If cursor = 0 Then cursor = 1
TextBox1.Select(cursor - 1, 0)
TextBox1.Focus()
End Sub
Private Sub Button_Saga_Click(sender As System.Object, e As System.EventArgs) Handles Button_Saga.Click
Dim cursor As Integer = FindCursor(TextBox1)
TextBox1.Select(cursor + 1, 0)
TextBox1.Focus()
End Sub
End Class
Bu işlemlerin hepsi sendkeys yontemi ile de yapılabilir.. Daha da kısa olur..
Sendkeys hakkında bilgi almak icin..
Maksat ufakta olsa yeni birşeyler oğrenmek..
Calışmalarınızda başarılar..
__________________
[Vb.Net] Imleci textbox icinde buton ile hareket ettirme
Programlama0 Mesaj
●26 Görüntüleme
- ReadBull.net
- Programlama ve Yazılım
- Programlama
- [Vb.Net] Imleci textbox icinde buton ile hareket ettirme