• 0

[vb .net] Go to Line in textbox/richtextbox


Question

Can anyone tell me the general idea of how to implement a "go to line number" in a textbox in vb .net? I know how to get the current line number, but I really can't figure out how to put the cursor at the beginning of a line number entered into a dialog. I found one example online, but it relied on the assumption that word wrap would be off which doesn't work in my case.

Any help would be appreciated.

14 answers to this question

Recommended Posts

  • 0

Public Sub [GoTo](ByVal ln As Integer)
  Win32.LockWindowUpdate(rtb.Handle)
  SelectionStart = Win32.SendMessage(rtb.Handle, Win32.EM.LINEINDEX, ln - 1, 0)
  Win32.LockWindowUpdate(IntPtr.Zero)

rtb.Focus()
End Sub

the lockwindowupdate calls aren't necessary, but they do help prevent flicker

Edited by Ianmac45
  • 0

I don't understand that either. I did it like this

Public Class TextBox2
    Inherits TextBox

    Public Property LineNumber()
        Get
            'i dunno
            Return 0
        End Get
        Set(ByVal value)
            Me.SelectionStart = 0

            For i As Integer = 1 To value
                SendKeys.Send("{DOWN           Next i
        End Set
    End Property

End Class

  • 0
  elliot said:
Me.SelectionStart = 0

I reset it the position to the top left. :)

586224601[/snapback]

Hmm, I guess that would work. I'm just worried about the execution time on a large file. The other day I was working on files from Firefox that are 10,000+ lines long and realized that finding line 5904 can be difficult. With your code, it could take a while to get to the line.

  • 0

mine does work

just include the lockwindowupdate and sendmessage api calls

i thought you guys would be able to figure it out, i guess not

Public Declare Auto Function LockWindowUpdate Lib "user32" (ByVal handle As IntPtr) As Boolean

Public Declare Auto Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal handle As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

  • 0

Ianmac45's will work fine, you just need to import the SendMessage and LockWindowUpdate (actually I've never used LockWindowUpdate before so I assume it's right) functions manually as Ianmac45 didn't include the Win32 unit.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • AdGuard is yet another app to block Windows Recall by Taras Buria Windows Recall is one of the most controversial Windows features. After the misfired launch and the scandal that followed, Microsoft implemented plenty of security measures and improvements. Still, some believe that Recall's reputation is tarnished forever. Besides, not everyone is comfortable with using the feature that takes screenshots of everything you do. As such, privacy-focused apps, browsers, and messengers are now offering blocks for Recall. AdGuard is the latest one to join them. AdGuard for Windows 7.21 introduces a new feature that lets you turn off Windows Recall. Although Recall is a strictly opt-in experience and it has several security measures, AdGuard developers believe that it is not enough. They argue that the feature idea itself is unsettling, PINs are easy to crack, and filters sometimes fail to engage. Here is what AdGuard says in the announcement post: If you use AdGuard on your PC, you can find the new "Disable Windows Recall" feature in Settings > Tracking Protection. As of now, Recall is only available on Copilot+ PCs. This month's non-security update expanded Recall to more users, making the feature available in the European Economic Area. And with Intel working on the next-generation desktop processors with improved NPUs, you can expect Recall and other recently introduced AI features to make their way to more users with desktop PCs. As an online publication, Neowin relies on ads for operating costs, and if you use an ad blocker, we'd appreciate being whitelisted. In addition, we have an ad-free subscription for $28 a year, which is another way to show support!
    • I'm sorry for sounding rude. I was just frustrated. I really want to get this right because I don't want to take any risk of potentially contaminating other hardware and risk losing precious files. Thanks again for the help. 
    • I am low-key enjoying the new start menu of 25H2 build. Looks like the management team who shoved the Recommended Section down our throats up till now got fired in recent gommage at MS. Also loving the 6Ghz Hotspot feature. I only enabled these 2 features and I am happy. I keep an eye on MDL forums for 26200.xxxx updates once a week to stay up to date manually. I downloaded the latest build from https://uupdump.net selected Dev Channel tab and downloaded amd64 build. Let the script ripp. Then I used vivetool to enable the above 2 features • 25H2 New Start Menu ViVeTool.exe /enable /id:47205210,49221331,49381526,49402389,49820095,55495322,48433719 • Enable Wifi 6Ghz Hotspot ViVeTool.exe /enable /id:40466470,48433719 Reboot and enjoy. Almost all the above info was provided by Neowin at some point.
    • Indeed, I do think its sad in some ways a corporation can never be content with "performing well across every metric" and having over £59 billion cash on hand.
    • They've been focusing on security and quality? Could have fooled me. Their own paying customers literally just got breached because they failed to push SharePoint updates downstream to on prem servers operating outside of their "365" ecosystem.
  • Recent Achievements

    • One Month Later
      Philsl earned a badge
      One Month Later
    • One Year In
      armandointerior640 earned a badge
      One Year In
    • One Month Later
      armandointerior640 earned a badge
      One Month Later
    • One Month Later
      Itbob513626 earned a badge
      One Month Later
    • Week One Done
      Itbob513626 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      615
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      156
    4. 4
      +FloatingFatMan
      122
    5. 5
      Michael Scrip
      116
  • Tell a friend

    Love Neowin? Tell a friend!