By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

cursor position

P: n/a
does any one know a way to determine the position of the
cursor in a text box. I would like to position a list next
to the current position for context commands. I am using
VS.NET/C#/System.Windows.Forms.
Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
txtSomething.SelectionStart is what you want

-----Original Message-----
does any one know a way to determine the position of the
cursor in a text box. I would like to position a list nextto the current position for context commands. I am using
VS.NET/C#/System.Windows.Forms.
.

Nov 15 '05 #2

P: n/a
I am not looking for the character number but the x,y
position on the form.
-----Original Message-----
txtSomething.SelectionStart is what you want

-----Original Message-----
does any one know a way to determine the position of the
cursor in a text box. I would like to position a list

next
to the current position for context commands. I am using
VS.NET/C#/System.Windows.Forms.
.

.

Nov 15 '05 #3

P: n/a
Steve,

I think textbox.Bounds is what your looking for. It holds everything you
might need about the location, size ect.

regards,

Marco
"Steve" <ho******@cmmts.com> wrote in message
news:02****************************@phx.gbl...
does any one know a way to determine the position of the
cursor in a text box. I would like to position a list next
to the current position for context commands. I am using
VS.NET/C#/System.Windows.Forms.

Nov 15 '05 #4

P: n/a
Thanks for the reponse Marco. This gives me a lot of
information, however I still can't seem to get the
position of the code insertion point in form coordinates.
I am starting to wonder whether I have to compare the size
of the text against the client rectangle and calculate
this every time ... or is there an easier way?
-----Original Message-----
Steve,

I think textbox.Bounds is what your looking for. It holds everything youmight need about the location, size ect.

regards,

Marco
"Steve" <ho******@cmmts.com> wrote in message
news:02****************************@phx.gbl...
does any one know a way to determine the position of the
cursor in a text box. I would like to position a list next to the current position for context commands. I am using
VS.NET/C#/System.Windows.Forms.

.

Nov 15 '05 #5

P: n/a
Steve,

I still not quite clear on what you are trying to do.
If you are trying to "float" a list next to the cursor position inside the
textbox, I think you are going to need to calculate the size of the string
inside the textbox and establish your location from there. I cant remeber
exacly where, but I have seen a class on the net that uses the
graphics.drawstring method to establish the length of a string in pixels.

Hope this helps.
I'm gone for the Holidays!

regards,

Marco
"Steve." <ho******@cmmts.com> wrote in message
news:01****************************@phx.gbl...
Thanks for the reponse Marco. This gives me a lot of
information, however I still can't seem to get the
position of the code insertion point in form coordinates.
I am starting to wonder whether I have to compare the size
of the text against the client rectangle and calculate
this every time ... or is there an easier way?
-----Original Message-----
Steve,

I think textbox.Bounds is what your looking for. It

holds everything you
might need about the location, size ect.

regards,

Marco
"Steve" <ho******@cmmts.com> wrote in message
news:02****************************@phx.gbl...
does any one know a way to determine the position of the
cursor in a text box. I would like to position a list next to the current position for context commands. I am using
VS.NET/C#/System.Windows.Forms.

.

Nov 15 '05 #6

P: n/a
Try Something like this,

I didn't test it, but I think this is what u are looking for.

TextBox textBox = new TextBox();
Graphics graphics = Graphics.FromHwnd(textBox.Handle);
SizeF size = graphics.MeasureString(textBox.Text.Substring(0,
textBox.SelectionStart), textBox.Font);
Point coord = textBox.Location.Offset((int) size.Width, (int) size.Height);

Regards,
Gustavo.

P.S.: this works if the textbox border is 0, to get the exactly position you
have to get the border size and add to the coordinate Point, I don't
remember right now what is the function or method, but I know it exist.
"Steve." <ho******@cmmts.com> wrote in message
news:01****************************@phx.gbl...
Thanks for the reponse Marco. This gives me a lot of
information, however I still can't seem to get the
position of the code insertion point in form coordinates.
I am starting to wonder whether I have to compare the size
of the text against the client rectangle and calculate
this every time ... or is there an easier way?
-----Original Message-----
Steve,

I think textbox.Bounds is what your looking for. It

holds everything you
might need about the location, size ect.

regards,

Marco
"Steve" <ho******@cmmts.com> wrote in message
news:02****************************@phx.gbl...
does any one know a way to determine the position of the
cursor in a text box. I would like to position a list next to the current position for context commands. I am using
VS.NET/C#/System.Windows.Forms.

.

Nov 15 '05 #7

P: n/a
To get the exact position, you're probably better off using api's and
sending an EM_POSFROMCHAR message to the textbox.

"Gustavo Franco" <gu************@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
Try Something like this,

I didn't test it, but I think this is what u are looking for.

TextBox textBox = new TextBox();
Graphics graphics = Graphics.FromHwnd(textBox.Handle);
SizeF size = graphics.MeasureString(textBox.Text.Substring(0,
textBox.SelectionStart), textBox.Font);
Point coord = textBox.Location.Offset((int) size.Width, (int) size.Height);
Regards,
Gustavo.

P.S.: this works if the textbox border is 0, to get the exactly position you have to get the border size and add to the coordinate Point, I don't
remember right now what is the function or method, but I know it exist.
"Steve." <ho******@cmmts.com> wrote in message
news:01****************************@phx.gbl...
Thanks for the reponse Marco. This gives me a lot of
information, however I still can't seem to get the
position of the code insertion point in form coordinates.
I am starting to wonder whether I have to compare the size
of the text against the client rectangle and calculate
this every time ... or is there an easier way?
-----Original Message-----
Steve,

I think textbox.Bounds is what your looking for. It

holds everything you
might need about the location, size ect.

regards,

Marco
"Steve" <ho******@cmmts.com> wrote in message
news:02****************************@phx.gbl...
> does any one know a way to determine the position of the
> cursor in a text box. I would like to position a list

next
> to the current position for context commands. I am using
> VS.NET/C#/System.Windows.Forms.
.


Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.