473,657 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textbox automatic sizing on giving input string

6 New Member
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 3045
vanc
211 Recognized Expert New Member
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
karan1981
6 New Member
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 Recognized Expert Expert
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
karan1981
6 New Member
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.Creat eGraphics();
SizeF size = g.MeasureString (_noteBody.Text , _noteBody.Font) ;
float lines = size.Width/_noteBody.Width ;
int linecheck = (int)lines;
if (linecheck < lines)
linecheck += 1;
_noteBody.Heigh t = _noteBody.Heigh t * 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 Recognized Expert Expert
I think it could work. Not sure if it has any advantages/disadvantages over doing it other ways.
Apr 7 '08 #6
karan1981
6 New Member
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 Recognized Expert Expert
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
karan1981
6 New Member
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 Recognized Expert Expert
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

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

Similar topics

2
13697
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 18:39:24 +0200 Local: Fri,Jul 15 2005 12:39 pm Subject: Re: Summer 2005 browsers' test set ?
5
12715
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 determine the width in twips for say Times New Roman 12, 35 characters or say Arial 11, 26 characters? Thanks, Steve
10
9082
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()); How do I get the number out of the text box if I only entered small positive integers? dave
7
2114
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 following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
10
1675
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
11983
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 form controls so
58
4644
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 the overhead of automatic variable sized arrays, I suspect it is smaller than that of malloc), although I'm not too worried about it. I was thinking that, with C99's variable length arrays, malloc shouldn't be needed most of the time. But I'm...
8
7122
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 used Join for that matter...But it was giving very unpredictable result all the time. I used Debug.print as well; but that was giving output in debug window and not in TextBox..i even tried my hand on Response.Write; but that was giving some kind of...
1
2450
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 and its rate should come in the next two cells...it should take from the data base... it's my code........ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <%@ page import="java.sql.*"...
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.