471,624 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

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

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
Nov 21 '05 #1
6 4525
Martin,
Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
both inherited from TextBoxBase?

Hope this helps
Jay
"Martin Heuckeroth" <ni**@nospam.invalid> wrote in message
news:52********************************@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

Nov 21 '05 #2

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]"
<Ja************@msn.com> wrote:
Martin,
Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
both inherited from TextBoxBase?

Hope this helps
Jay
"Martin Heuckeroth" <ni**@nospam.invalid> wrote in message
news:52********************************@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


Nov 21 '05 #3
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" <ni**@nospam.invalid> wrote in message
news:ri********************************@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]"
<Ja************@msn.com> wrote:
Martin,
Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
both inherited from TextBoxBase?

Hope this helps
Jay
"Martin Heuckeroth" <ni**@nospam.invalid> wrote in message
news:52********************************@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

Nov 21 '05 #4

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
On Tue, 22 Feb 2005 12:03:48 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
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" <ni**@nospam.invalid> wrote in message
news:ri********************************@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]"
<Ja************@msn.com> wrote:
Martin,
Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
both inherited from TextBoxBase?

Hope this helps
Jay
"Martin Heuckeroth" <ni**@nospam.invalid> wrote in message
news:52********************************@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


Nov 21 '05 #5
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" <ni**@nospam.invalid> wrote in message
news:ls********************************@4ax.com...

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
On Tue, 22 Feb 2005 12:03:48 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
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" <ni**@nospam.invalid> wrote in message
news:ri********************************@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]"
<Ja************@msn.com> wrote:

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

Hope this helps
Jay
"Martin Heuckeroth" <ni**@nospam.invalid> wrote in message
news:52********************************@4ax.co m...
> 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

Nov 21 '05 #6

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

On Wed, 23 Feb 2005 09:05:53 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
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" <ni**@nospam.invalid> wrote in message
news:ls********************************@4ax.com.. .

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
On Tue, 22 Feb 2005 12:03:48 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
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" <ni**@nospam.invalid> wrote in message
news:ri********************************@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]"
<Ja************@msn.com> wrote:

>Martin,
>Have you tried RichTextBox.SelectionStart & RichTextBox.SelectionLength,
>both inherited from TextBoxBase?
>
>Hope this helps
>Jay
>
>
>"Martin Heuckeroth" <ni**@nospam.invalid> wrote in message
>news:52********************************@4ax.c om...
>> 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
>


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Woody Splawn | last post: by
5 posts views Thread by vj_dba | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.