Results 1 to 5 of 5

Thread: Line display Notepad application

Hybrid View

  1. #1

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Line display Notepad application

    vb Code:
    1. Private Sub RichTextBox1_EnterKeyPressed(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
    2.         Dim numlinecount As Integer
    3.         If e.KeyData = Keys.Enter Then
    4.             numlinecount = (RichTextBox2.GetLineFromCharIndex(RichTextBox2.Text.Length)) + 1
    5.             RichTextBox2.AppendText(CStr(numlinecount) & vbLf)
    6.         End If
    7.     End Sub

    Option strict is almost always on for me, because I like to know how the conversions are with my application to reduce any conversion conflictions as well.

    Here's my current code so far where rtb1 is the main editor, and rtb2 is the line display on the left side like in notepad++. So far my code allows for a number to be added on a new line in the line display when the enter key is pressed, however I want to know how I can get rid of those numbers whenever a backspace or deleted selection of text or the delete key erases a {vbLf} entry in rtb1 so that I can remove the integers on the left side accordingly to keep up with an accurate line count display. Also adding the number of "lines" (as integers/numbers) to that left hand display depending on how many {vbLf} entries there are in a pasted clipboard.

    Then that should cover everything about the line display, except for loading a document and automatically displaying the number of lines in the text. I believe i'd have to count the number of occurences of {vbLf} upon opening a document, but I haven't tried yet, so i'm not sure how slow or fast that would render opening a document.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Line display Notepad application

    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Line display Notepad application

    Hmm, your code seems to work, but i'm having a few issues with it, for some reason the horizontal scrollbar doesn't want to work on the richttextbox i'm using for the control (not using a multiline textbox), and also after holding down enter, and the panel items get expanded in size, after holding down the backspace button the selected index on the line display seems to be off (it's down one from the level of the ibeam in the richtextbox. But before the control gets expanded it's correct. Although when I backspace ALL the way to line 1 the scrollbar doesn't want to scroll all the way to the top, and the first line is kind of cut off at the top as a result. These are the 2 issues i'm having.

    I'm adjusting the width of the controls horizontally for when I have word wrap on and off. The line display I have off when word wrap is on, and the richtextbox takes up the entire witdh overlapping everything, then I just expanded the width of the panel outside of the form to hide the vertical scrollbar there, and enabled the vertical scrollbar on the rtb control since in wordwrap the horizontal one is useless.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  4. #4

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Line display Notepad application

    I was wondering how you would get the mouse scroll of the rtb as an event to handle the panel scroll? I'm having issues with that as well, and for the size of the control i'm assuming, it seems to be a bit slow with a large line count, I might have to add multithreading to it in any case to have a chance at making it a bit faster.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  5. #5

    Thread Starter
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Line display Notepad application

    Alright, an update, I got the horizontal scrollbar, but it 'expands' outside of the view of the form when you have lots of lines and the panel scrollbar is near the top for it's position. You only see it when you're scrolled all the way down:

    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width