473,386 Members | 1,621 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,386 software developers and data experts.

How do I set a TextBox width acorrding to a string?

Udi
Hi,
I have a simple multiline TextBox which I need to set its width
according to the longest line in Lines.
I assume I need to calculate the font width, how do I do that?
Thanks!

May 8 '06 #1
2 1915
There is a method on the graphics object Graphics.MeasureString this will
tell you the height and width of the text.
http://www.codeproject.com/cs/media/measurestring.asp includes a simple
version using MeasureString and offers an alternative methodology.

Cheers,

Greg Young
MVP - C#
"Udi" <Ud**********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Hi,
I have a simple multiline TextBox which I need to set its width
according to the longest line in Lines.
I assume I need to calculate the font width, how do I do that?
Thanks!

May 8 '06 #2
Just a quick note.
..NET 2.0 has TextRenderer class that provides more accurate measuring of a
text.
--
HTH
Stoitcho Goutsev (100)

"Greg Young" <Dr*************@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP04.phx.gbl...
There is a method on the graphics object Graphics.MeasureString this will
tell you the height and width of the text.
http://www.codeproject.com/cs/media/measurestring.asp includes a simple
version using MeasureString and offers an alternative methodology.

Cheers,

Greg Young
MVP - C#
"Udi" <Ud**********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Hi,
I have a simple multiline TextBox which I need to set its width
according to the longest line in Lines.
I assume I need to calculate the font width, how do I do that?
Thanks!


May 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve | last post by:
Visual Studio 2003 .NET C# I am trying to change the width of a textbox at run time, to fit in the text it contains. How can I do this? Thanks Steve
3
by: Ronald S. Cook | last post by:
Hi all, I have an ASP.NET DataGrid wherein there is an edit link for each row. Upon clicking the link, certan fields in that row display in text boxes so that they may be edited. I would like...
4
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
1
by: melanieab | last post by:
Hi again, I have a textbox where the text is longer than the textbox width. When I type something in there or even do any single keystroke (other than tab, up, down, or enter) and then leave, the...
2
by: Calvin KD | last post by:
Hi everyone, I have a number of textboxes, lined up in a html table. I have split the table into different columns. The column widths are all relative, that is, % rather pixels or points so that...
8
by: Filipe Marcelino | last post by:
Hi, I'm trying to create a textbox inheriting from the standard textbox. I would like to: 1. repaint the textbox border; 2. define a color for that border; Till now I made this:
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
1
by: savajx1 | last post by:
I need to dynamically create a set of bound fields contained in a GridView control. I also have a single static CommandField that I can declare in the Columns <tagof the GridView control. I have...
0
KalariaNitya
by: KalariaNitya | last post by:
Hello, could anybody help me? i have gridview, inside gridview i have one Update button & textbox update button update the quantity entered in textbox. i want to update the quantity on textbox on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.