bangbang023 Veteran Posted October 29, 2004 Veteran Share Posted October 29, 2004 I'm havign a real bad day and have had no luck finding any non vb6 code for this: Simply, how do I find the current line (maybe comumn too) in a textbox in vb. net? Link to comment Share on other sites More sharing options...
0 Winston Posted October 29, 2004 Share Posted October 29, 2004 Errrr are you trying to find where the current caret position is? if so Me.TextBox1.SelectionStart would give u the position. Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 29, 2004 Author Veteran Share Posted October 29, 2004 yes, but that doesn't give a line number. Link to comment Share on other sites More sharing options...
0 htimsneb Posted October 29, 2004 Share Posted October 29, 2004 Try: taken from http://www.vb-helper.com/howto_track_textbox_caret.html Private Sub CheckPosition() Dim char_pos As Long Dim row As Long Dim col As Long char_pos = SendMessage(Text1.hwnd, EM_GETSEL, 0, 0) char_pos = char_pos \ &H10000 row = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, _ char_pos, 0) + 1 col = char_pos - SendMessage(Text1.hwnd, EM_LINEINDEX, _ -1, 0) + 1 lblPosition.Caption = "(" & Format$(row) & ", " & _ Format$(col) & ")" End Sub Private Sub Text1_KeyDown(KeyCode As Integer, Shift As _ Integer) CheckPosition End Sub Private Sub Text1_KeyUp(KeyCode As Integer, Shift As _ Integer) CheckPosition End Sub Private Sub Text1_MouseDown(Button As Integer, Shift As _ Integer, X As Single, Y As Single) CheckPosition End Sub Private Sub Text1_MouseUp(Button As Integer, Shift As _ Integer, X As Single, Y As Single) CheckPosition End Sub Link to comment Share on other sites More sharing options...
0 +primortal Subscriber² Posted October 29, 2004 Subscriber² Share Posted October 29, 2004 found this on google groups http://www.google.de/groups?q=EM_LINEFROMC....phx.gbl&rnum=1 Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 29, 2004 Author Veteran Share Posted October 29, 2004 found this on google groupshttp://www.google.de/groups?q=EM_LINEFROMC....phx.gbl&rnum=1 584827570[/snapback] thank you. That code works perfectly. htimsneb: thanks but that is vb6 Link to comment Share on other sites More sharing options...
0 Winston Posted October 30, 2004 Share Posted October 30, 2004 Hmmm yeah seems not so flexible, why not change to a RichTextBox MessageBox.show(Me.RichTextBox1.GetLineFromCharIndex(Me.RichTextBox1.SelectionStart)) that exactly achieves what you want. Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 30, 2004 Author Veteran Share Posted October 30, 2004 gah richtext boxes have that built in like that? maybe I should now. Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 30, 2004 Author Veteran Share Posted October 30, 2004 bah richtextboxes don't seem to like darg and drop all that much Link to comment Share on other sites More sharing options...
0 Winston Posted October 30, 2004 Share Posted October 30, 2004 bah richtextboxes don't seem to like darg and drop all that much 584830942[/snapback] ellaborate a little, what do you mean? Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 30, 2004 Author Veteran Share Posted October 30, 2004 meaning natively it doesn't have support for it. There are some work around "hacks" but it's not worth it just to simplify the current line number method. Link to comment Share on other sites More sharing options...
0 Winston Posted October 30, 2004 Share Posted October 30, 2004 meaning natively it doesn't have support for it. There are some work around "hacks" but it's not worth it just to simplify the current line number method. 584831062[/snapback] do you mean drag and drop files into the richtextbox? Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 30, 2004 Author Veteran Share Posted October 30, 2004 yes. works fine with textboxes but after trying ot get it to work with richtext and looking online, it seems as though it's not as "accessible" as it is with textboxes. Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted October 30, 2004 Share Posted October 30, 2004 yes. works fine with textboxes but after trying ot get it to work with richtext and looking online, it seems as though it's not as "accessible" as it is with textboxes. 584833023[/snapback] why is not as accessible? I'm looking at the control and it supports d-n-d. Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 30, 2004 Author Veteran Share Posted October 30, 2004 I don't know, but it doesn't work at all for me. Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted October 30, 2004 Share Posted October 30, 2004 I don't know, but it doesn't work at all for me. 584834030[/snapback] May I see your DragDrop handler code? <edit>I just got it to work dragging from a listbox to a richtextbox. This is all i needed in the richtextbox DragDrop event handler richTextBox1.SelectedText = e.Data.GetData("System.String", true).ToString(); Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 30, 2004 Author Veteran Share Posted October 30, 2004 im dragging and dropping from explorer.......I have a textbox in a child form. I put the drag drop event in the parent form and t picks it up fine. Does not do so with the richtextbox. I tired localizing the drop drop code from the parent form to the childform and have it only read drag drop events on the richtextbox itself and still nothing. This is the code I'm using in the parent form: Private Sub mainForm_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then e.Effect = DragDropEffects.All Else e.Effect = DragDropEffects.None End If End Sub Private Sub mainForm_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop Dim number As Integer = noteArray.Count Dim title As String 'get file name and location Dim s() As String = e.Data.GetData("FileDrop", False) Dim i As Integer = 0 While i < s.Length 'creates a new notepad window Call createNewPad() title = s(i).Substring(s(i).LastIndexOf("\") + 1) noteArray(number).text = title Me.tabPads.TabPages(number).Text = title 'open file and input text into txtMain Dim dragStream As New System.IO.FileStream(s(i), IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read) Dim dragReader As New System.IO.StreamReader(dragStream) noteArray(number).txtMain.text = dragReader.ReadToEnd dragReader.Close() dragStream.Close() noteArray(number).txtMain.select(0, 0) noteArray(number).fileNameExists = True noteArray(number).contentchanged = False noteArray(number).filenamesaved = s(i) number = number + 1 i = i + 1 End While 'give focus to NexPad Me.Activate() noteArray(i).txtMain.focus() End Sub Even when I specifically set it to the rich text box, still no go. Link to comment Share on other sites More sharing options...
0 bangbang023 Veteran Posted October 30, 2004 Author Veteran Share Posted October 30, 2004 um nevermind lol. I must have done something wrong cause it works fine now. Link to comment Share on other sites More sharing options...
Question
bangbang023 Veteran
I'm havign a real bad day and have had no luck finding any non vb6 code for this:
Simply, how do I find the current line (maybe comumn too) in a textbox in vb. net?
Link to comment
Share on other sites
17 answers to this question
Recommended Posts