Click here to Skip to main content
15,748,930 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
how would i go about

getting the y position of a TextBox.Text

what i mean is as follows :

i have a textbox with scroller

messages where writen to it

// inside the textbox

hello how are u?

whats up?

bla bla bla...

// now in this position i would like to append a button control
// but i cant fingure out how to get the position to set the control in
// im looking for somthing sort of a line index type property

x_panel.Location = new Point(rtb_send.Width / 2 -x_panel.Width / 2,??? <big>Height</big> ???);

SAKryukov is right - you will expend a lot of effort for a very low reward.

Have you considered using a GridView or a DataGridView instead? If you have a text column and a button column, that would keep them together.
Share this answer
Sergey Alexandrovich Kryukov 16-Jan-11 14:53pm    
That's correct - a 5.
There could be several nice designs.
Espen Harlinn 16-Jan-11 15:43pm    
5+ The improved solution :)
In principle, you could do it. You can reproduce exact same text up the the point you need and calculate text metrics.
This is where to start:[^], but...

Don't do it!

This is a very, very bad idea. You're going to spend disproportionally long time to obtain very unreliable result. When you do it, you will have to struggle will your edit control going on top of your button when focused -- what event should be showing your button on top again? you will have to catch all events of scrolling the text (you mentioned scrolling yourself) or modification of the text, because any of those will mess up your layout.

Most likely, you will get the satisfactory behavior a little later than never :) .
Share this answer
Manfred Rudolf Bihy 16-Jan-11 14:37pm    
I agree that doing this is a bad idea! 5+
(I think bold and maybe screaming it would have sufficed though, that red is burning my eyes :) )
Sergey Alexandrovich Kryukov 16-Jan-11 14:56pm    
Whatever you say, Manfred :-) This is because the page CSS made it orange which I did not like as well... :-) -- thanks for your vote.
Manfred Rudolf Bihy 16-Jan-11 15:24pm    
Ahhhh, that looks better already!
Espen Harlinn 16-Jan-11 15:42pm    
5+ Sounded like an odd idea - if he wan't from the US I would have put it down to a linguistic problem :)
Sergey Alexandrovich Kryukov 16-Jan-11 16:27pm    
As I say to Griff, the idea is odd, explanation is more or less clear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900