473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Textbox automatic sizing on giving input string

Hi,

I have a user control that has a textbox.
This user control is placed in a form at runtime. This form gives a string to the user control and the textbox is to show this in multiple lines.(i do so using a property to set the textbox's text property)
So in designer view i set the multiline property to TRUE and
the word wrap property to TRUE.
This enables the text to be shown in multiple lines at runtime.
But the textbox size does not grow according to the number of lines of text that it contains.
I dont want to use scrolls.
Please suggest how to set the size of the textbox to adjust according to the number of lines it has at runtime. So that all lines are shown. and i can accordingly place other contols below it.

Thanks
Apr 6 '08 #1
10 3009
vanc
211 Expert 100+
Hi,

I have a user control that has a textbox.
This user control is placed in a form at runtime. This form gives a string to the user control and the textbox is to show this in multiple lines.(i do so using a property to set the textbox's text property)
So in designer view i set the multiline property to TRUE and
the word wrap property to TRUE.
This enables the text to be shown in multiple lines at runtime.
But the textbox size does not grow according to the number of lines of text that it contains.
I dont want to use scrolls.
Please suggest how to set the size of the textbox to adjust according to the number of lines it has at runtime. So that all lines are shown. and i can accordingly place other contols below it.

Thanks
You can calculate the number of characters that will reach the textbox's edge and resize the textbox according to the number of entered characters. Cheers.
Apr 7 '08 #2
You can calculate the number of characters that will reach the textbox's edge and resize the textbox according to the number of entered characters. Cheers.
Hi Vanc

Thanks for replying.
Basically In designer view, My textbox just fits in one line of string.
At runtime it could get a very long string.
Thus as Multiline is true, the rest of the text comes in the next line and so on.
But unfortunetely my textbox size remains the same.
I need it to grow(vertically) with the numbers of line at runtime.
I dont want to use scroll bars.
could u please suggest how to go about this.
Is the best way to know how many characters can fit in a single line and then divide total characters by that, to know the number of lines. and then resize by that many times?
or is it better to use a label instead. i never have to take user input. i just need to display the string at runtime in multiple lines.

Thanks alot. really appreciate your help.
Karan
Apr 7 '08 #3
Plater
7,872 Expert 4TB
As was suggested, compute the number of characters in the string you have, divide by the number of allowable characters wide in the textbox (it's a property, you can set it) and determine how many rows to make your textbox show.
Apr 7 '08 #4
As was suggested, compute the number of characters in the string you have, divide by the number of allowable characters wide in the textbox (it's a property, you can set it) and determine how many rows to make your textbox show.
Hi Plater

Thanks for replying too.
My textbox is "_noteBody"
This is what i wrote in a function after the textbox gets the long string :-

Graphics g = _noteBody.CreateGraphics();
SizeF size = g.MeasureString(_noteBody.Text, _noteBody.Font);
float lines = size.Width/_noteBody.Width;
int linecheck = (int)lines;
if (linecheck < lines)
linecheck += 1;
_noteBody.Height = _noteBody.Height * linecheck;

I did the "+=1" incase the division ended up to be something like 3.5 or something. So that i get a another line for that.

Please suggest if this is appropriate.
Thanks alot.
Apr 7 '08 #5
Plater
7,872 Expert 4TB
I think it could work. Not sure if it has any advantages/disadvantages over doing it other ways.
Apr 7 '08 #6
I think it could work. Not sure if it has any advantages/disadvantages over doing it other ways.
Hi Plater

Thanks for replying.
A) But how else to calculate the number of strings that can fit in a single line?
B) Also how to make a textbox transparent? it does not let me set the backcolor property to transparent. Is there any way to do this. I did google for this but could not find a easy solution.
C) lastly how to vertically center the text in a textbox.

I really appreaciate your help.
Thanks
Apr 9 '08 #7
Plater
7,872 Expert 4TB
well you have a string that is going into the textbox yes?
You know how many characters are in that with .Length property.
In web applications, the multi-line textboxes have a Rows and Columns property where you can set/get how man characters per row (Columns) and how many Rows to show.
If you set your textbox to 80 Columns, dividing your string's length by 80 (and possibly adding 1 to handle "rounding") you should get the value you would set to Rows.
Apr 9 '08 #8
well you have a string that is going into the textbox yes?
You know how many characters are in that with .Length property.
In web applications, the multi-line textboxes have a Rows and Columns property where you can set/get how man characters per row (Columns) and how many Rows to show.
If you set your textbox to 80 Columns, dividing your string's length by 80 (and possibly adding 1 to handle "rounding") you should get the value you would set to Rows.
Thanks Plater.
I have a system.Forms application. Will try on that.
Also regarding the issue of making the textbox transparent, any ideas...

thanks
karan
Apr 9 '08 #9
Plater
7,872 Expert 4TB
Thanks Plater.
I have a system.Forms application. Will try on that.
Also regarding the issue of making the textbox transparent, any ideas...

thanks
karan
Ugh, sorry. Was stuck on web application.
Even when I went "but web applications don't have graphics objects for their textboxes...." it didn't occur to me.

The graphics method would be prefered then I think.
Apr 9 '08 #10
Hey thats fine. My mistake i didnt spcify.
Thanks alot :)
Apr 9 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005...
5
by: Steve | last post by:
I need a way to programatically change the width of a textbox to display all the data knowing the font, font size and number of characters. Does any oone know of a reference somewhere ot a way to...
10
by: Dave | last post by:
I can't get a number out of my textbox. it keeps giving me an error and saying that the input string was not in the correct format. this.number = int.Parse((this.numberTextBox.Text.ToString()); ...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
10
by: Per W. | last post by:
Is it possible to have dynamic size on a textbox? If the context is only one line then the box is only one line, but if the context is 10 lines then the box adjust to this? /Per W.
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
58
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is...
8
Parul Bagadia
by: Parul Bagadia | last post by:
Hello folks, I tried lot many methods for displaying an array in textbox, i thought of converting that array in string; so that i can directly assign it to textbox as textbox is also a string; i...
1
by: rakeshnair | last post by:
i wrote a code in jsp to create dynamic table..the problem is i need data base connection when cursor moves from one cell to other... eg...when i enter product id in the first cell, the product name...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.