Results 1 to 5 of 5

Thread: [RESOLVED] How to make a contextMenuStrip to scroll to a position on a RichTextBox

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    114

    Resolved [RESOLVED] How to make a contextMenuStrip to scroll to a position on a RichTextBox

    Am trying to make a contextMenuStrip to scroll to a certain position on a RichTextBox on the selected text. When you use a small file on the RichTextBox, it is working perfectly... But when you use a large file, the Menustrip cannot scroll to that position with the help of the scrollbars on the RichTextBox. How can I solve this problem from the code here:

    Where word is selected on:

    Code:
     ContextMenuStrip1.Show(RichTextBox1, RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart + RichTextBox1.SelectionLength))

    Show the Menu under the selected text on the RichTextBox:


    Code:
        Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
    
            Try
                With RichTextBox1
                    Dim pt As Point = Me.PointToClient(.PointToScreen(.GetPositionFromCharIndex(.SelectionStart)))
                    pt.Y += .Font.Height ' * Assuming all text use same Font/Height!
                    ContextMenuStrip1.Show(PointToScreen(pt))
                End With
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Exception Window", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
            End Try
            Exit Sub
        End Sub
    Last edited by nqioweryuadfge; Sep 28th, 2017 at 07:23 AM.

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