Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27203

[RESOLVED] Pasting in Textbox - Jumping to top

$
0
0
Hi,
I took a couple of classes on VB.Net last year and wanted to keep up with what little bit I did learn, so I wrote an HTML tagging program and am just adding things as I go, basically learning. It has all the HTML buttons and pastes them in the textbox and keeps up with when the closing tags need to be added and such. It does some other neat things too, but to get to the point, when I paste text into the textbox that exceeds the height (and the scroll bar appears), the textbox jumps back to the top every time, making me scroll all the way back down, and pretty much makes tagging long texts not worth the effort.

I only have Visual Studio Express 2010, and in looking online at some of the solutions, one of them gives a snippet of code to put in the page_load event, but I can't find the page_load event when I look under 'form events.' This is an example of one of the buttons, and how I have it pasting in the textbox. I want the cursor to always show up at the end of the text or at that end of the tag that is placed in the textbox. Does this look like the best way to do it (I looked online for awhile and this seemed to be best, but it may be causing the problem. Does anyone know what I can do to stop it from jumping back to the top without me having to have too much advanced knowledge :D

Code:

Dim insertPos As Integer = txtString.SelectionStart
        Dim strTag As String

        If btnDiv.Text = "<div>" Then
            strTag = "<div>"
            txtString.Text = txtString.Text.Insert(insertPos, strTag)
            txtString.SelectionStart = insertPos + strTag.Length
            txtString.Focus()
            btnDiv.Text = "</div>"
        Else
            strTag = "</div>"
            txtString.Text = txtString.Text.Insert(insertPos, strTag)
            txtString.SelectionStart = insertPos + strTag.Length
            txtString.Focus()
            btnDiv.Text = "<div>"
        End If

Thanks in advance if anyone can help. I've spent hours on this little meaningless project, but I have learned a lot.

Viewing all articles
Browse latest Browse all 27203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>