• 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

    • I'd say this is hardly news. A GUI wrapper is not exactly some grand accomplishment. Even ClamAV itself is of questionable use. I suppose it lets you check the box on an audit questionnaire that a server has virus protection. Linux has always been a more difficult target for malware because of the wide variety of distros, library versions, etc.
    • Privacy nightmare... And, yes, I know, there's an On/Off toggle. But like Edward Snowden once said : "Where there's an On/Off toggle, there's always a way to turn it on." 😉 Microsoft is also working on letting Copilot tap into your history and credentials so that it can better understand context and perform actions on your behalf
    • Looks like "LoucheBear" should be renamed "DoucheBear". Ignorant ######.
    • The dev is a snowflake for deciding that a project he’s not getting paid to do isn’t worth the attacks? Interesting.
    • Microsoft explains how organizations can use Intune to upgrade from Windows 10 to Windows 11 by Usama Jawad The timer for Windows 10's end of life is counting down and while organizations can pay for Extended Security Updates (ESU), it might not be financially feasible for them to do so. In cases like these, it is in both the enterprise customer and Microsoft's benefit to upgrade to Windows 11 as seamlessly as possible. To that end, the Redmond tech giant has published a detailed guide explaining how companies can upgrade to Windows 11 through Intune. Microsoft has emphasized that this guide is primarily intended for domain-joined or co-joined Windows 10 PCs in order to perform a cloud-native migration to a state where the device is running on Windows 11 and is Entra-joined with Intune. To get started, customers obviously need to confirm that their hardware meets the requirements for Windows 11, which includes the dreaded TPM 2.0. This can be confirmed through Microsoft Configuration Manager or Endpoint Analytics in Intune. In addition, tools like Windows Autopatch, Configuration Manager, and Windows Server Update Services (WSUS) should be employed to update Windows 10 devices to the latest supported version, which is version 22H2. IT admins should also synchronize identities from Active Directory (AD) to Entra ID, configure and validate a hybrid join, prepare the Intune environment with the required licenses and admin roles, and enable co-management in Intune and Configuration Manager. Next, Group Policy Objects (GPOs) should be rationalized, redundant policies should be replaced, Intune configuration profiles should be set up, and Intune policies should be configured to deploy the update in phases. Then, Windows Autopatch should be leveraged to deliver the update and monitor the rollout. Applications should also be migrated from Configuration Manager to Intune for packaging, testing, deploying, and assigning them to the correct device groups. IT admins should also be vigilant in decommissioning the old deployments in Configuration Manager and updating the relevant documentation. The final step of this process involves transitioning from a domain network-joined setup to Entra ID-joined. This is a multi-step process, so make sure to check out the details here. Microsoft believes that this cloud-native migration approach will ensure centralized and streamlined management, enhanced security, an optimized UX, reduced reliance on legacy infrastructure, and allow IT admins to leverage Copilot in Intune.
  • Recent Achievements

    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
    • One Month Later
      James_kobe earned a badge
      One Month Later
    • Week One Done
      James_kobe earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      656
    2. 2
      ATLien_0
      253
    3. 3
      Xenon
      167
    4. 4
      neufuse
      146
    5. 5
      +FloatingFatMan
      121
  • Tell a friend

    Love Neowin? Tell a friend!