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

M

Martin Heuckeroth

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
 
J

Jay B. Harlow [MVP - Outlook]

Martin,
Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
both inherited from TextBoxBase?

Hope this helps
Jay
 
M

Martin Heuckeroth

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
 
J

Jay B. Harlow [MVP - Outlook]

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 :-|

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
 
M

Martin Heuckeroth

Jay,

Thx for being persistent. We took another and better look at the
SelectionStart and yes it works.

Btw why do you recommend that we save the SelectionLength also?

Martin
 
J

Jay B. Harlow [MVP - Outlook]

Martin,
In case the user had any text selected, saving SelectionLength (in addition
to SelectionStart) will save the "selection" as well.

If there is "There is no editing or any modifying in the box." it may not be
as important. However as soon as a user had text selected & it (the fact
that there was a selection) disappears they may get upset...

Its similar to VB6 add-ins that clear the clipboard when they start, simply
as that's the only way to set custom toolbar icons.

Hope this helps
Jay

Martin Heuckeroth said:
Jay,

Thx for being persistent. We took another and better look at the
SelectionStart and yes it works.

Btw why do you recommend that we save the SelectionLength also?

Martin


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 said:
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]"

Martin,
Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
both inherited from TextBoxBase?

Hope this helps
Jay


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
 
M

Martin Heuckeroth

Jay,
Good point thx. We didn't think of that because we are working on a
read only box. We have that working now.
Martin

Martin,
In case the user had any text selected, saving SelectionLength (in addition
to SelectionStart) will save the "selection" as well.

If there is "There is no editing or any modifying in the box." it may not be
as important. However as soon as a user had text selected & it (the fact
that there was a selection) disappears they may get upset...

Its similar to VB6 add-ins that clear the clipboard when they start, simply
as that's the only way to set custom toolbar icons.

Hope this helps
Jay

Martin Heuckeroth said:
Jay,

Thx for being persistent. We took another and better look at the
SelectionStart and yes it works.

Btw why do you recommend that we save the SelectionLength also?

Martin


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


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]"

Martin,
Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
both inherited from TextBoxBase?

Hope this helps
Jay


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top