Re: Help on "GetPositionFromCharIndex(ByVal index As Integer) As Point"

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 02/22/05


Date: Tue, 22 Feb 2005 12:03:48 -0600

Martin,
> Jay, thx for your answer but I believe that's not it.
Again, have you tried it? :-|

Are you asking where the mouse Cursor is or the text caret? Normally when
people as for "save my position" its text caret (although they state
"cursor"), in which case SelectionStart is what they are wanting. To get the
Mouse Cursor position you can use Control.MousePosition, however I don't
know of a .NET method to set the mouse position, IMHO moving the mouse
Cursor can be rather disruptive to the user anyway :-|

>>> So my guestion is how can we store the x,y coordinates of the cursor
>>> in the richtextbox so we can restore the cursor position after the
>>> refresh.

Use RichTextBox.SelectionStart as it is the position of the caret in your
RichTextBox. Rather then being row & column it is number of characters from
the beginning of the RichTextBox.

Something like:

    Dim position As Integer = RichTextBox1.SelectionStart
    RichTextBox1.Refresh
    RichTextBox1.SelectionStart = position

I would recommend also saving the RichTextBox.SelectionLength as well.

Hope this helps
Jay

"Martin Heuckeroth" <nick@nospam.invalid> wrote in message
news:ripm11pset8qeoh7j0g1v2pieigjl40ac8@4ax.com...
>
> Jay, thx for your answer but I believe that's not it.
>
> There is no editing or any modifying in the box. I need to find a way
> to read the coordinates/position where i am in the richtextbox before
> i do a refresh and it resets so i can return it to where it was before
> i did the refresh. Like when i scrolled down to row 255 the refresh
> will return me to row 1 and i need to go back manuallly to row 255. We
> are blank here en I need a solution to have that done for me instead
> of looking up where i was.
>
> Martin
>
>
> On Tue, 22 Feb 2005 09:58:29 -0600, "Jay B. Harlow [MVP - Outlook]"
> <Jay_Harlow_MVP@msn.com> wrote:
>
>>Martin,
>>Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
>>both inherited from TextBoxBase?
>>
>>Hope this helps
>>Jay
>>
>>
>>"Martin Heuckeroth" <nick@nospam.invalid> wrote in message
>>news:52km11tcokkr02rto9m9qo1vp4te4qg4jo@4ax.com...
>>> Hi,
>>>
>>> We are looking for a way to determine the x and y points of the cursor
>>> in a richtext box.
>>>
>>> We made an VB.NET application with a couple of listboxes and one of
>>> them is a richtextlistbox. After a refresh the cursor of the
>>> richtextlistbox is reset and goes to top. And that's not a cool thing
>>> when you are reading at the bottom of that box and have to look up the
>>> point where your were reading manual to have it reset after another
>>> refresh.
>>>
>>> So my guestion is how can we store the x,y coordinates of the cursor
>>> in the richtextbox so we can restore the cursor position after the
>>> refresh.
>>>
>>>
>>> Dim nSearch As Integer = ListBoxSearchItems.SelectedIndex
>>>
>>> Dim nTeamroom As Integer = ListBoxTeamroom.SelectedIndex
>>>
>>> Dim nRow As Integer = RichTextBoxMemo.
>>> Dim nColumn As Integer = RichTextBoxMemo.
>>> RefreshDataSet()
>>>
>>> If (nSearch > -1) And (nSearch < ListBoxSearchItems.Items.Count)
>>> Then ListBoxSearchItems.SetSelected(nSeach, True)
>>>
>>> If (nTeamroom > -1) And (nTeamroom < ListBoxTeamroom.Items.Count)
>>> Then ListBoxTeamroom.SetSelected(nTeamroom, True)
>>>
>>>
>>> SeekInfo()
>>>
>>>
>>> We started playing with the "GetPositionFromCharIndex(ByVal index As
>>> Integer) As Point" function but don't get that to work. Any code will
>>> be apperciated.
>>>
>>> thx, Martin
>>
>



Relevant Pages

  • Re: Help on "GetPositionFromCharIndex(ByVal index As Integer) As Point"
    ... thx for your answer but I believe that's not it. ... to read the coordinates/position where i am in the richtextbox before ... i do a refresh and it resets so i can return it to where it was before ... After a refresh the cursor of the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Using Office and Windows XP, SP3
    ... Jay, one last question. ... with the cursor on row 2 (as the ... Your macro can use code like this to determine which row contains the form field ... I think you'll find that the fields in the first row have ...
    (microsoft.public.word.vba.general)
  • Re: New doc starts on top edge of page?
    ... Thanks very much Jay - yet another tick box I hadn't noticed! ... Regards, ... >>I notice that when copying text from the web into Word for reformatting ... >>the cursor moves down to the proper position. ...
    (microsoft.public.word.application.errors)
  • Re: Change ROW colors in a grid.
    ... others are saying if I create another table or cursor. ... you address the columns but not the rows in the grid. ... added lcolor and refresh that ... If you change filter or order in your table, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: insert cursor
    ... Jay wrote: ... but couldn't get the cursor to move there when I clicke din the ... welcome to the Mac! ... with two buttons or more--I don't like Apple's mice, ...
    (microsoft.public.mac.office.word)