473,811 Members | 3,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textbox resize problem

Hello all,
I am trying to resize a textbox to exactly fit the contents. The
method I am using gets it close but it is just a little bit too small.
Could someone tell me where I am going wrong here please?

/* SYSTEM GENERATED FOR THE TEXTBOX */
//
// txt
//
this.txt.Border Style = System.Windows. Forms.BorderSty le.None;
this.txt.Font = new System.Drawing. Font("Microsoft Sans Serif", 8.25F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.txt.Locati on = new System.Drawing. Point(72, 48);
this.txt.MaxLen gth = 100;
this.txt.Name = "txt";
this.txt.Size = new System.Drawing. Size(288, 13);
this.txt.TabInd ex = 2;
this.txt.Text = "Test String";

/* MY CODE */
SDR.Graphics g = txt.CreateGraph ics();
SDR.Font fnt = new SDR.Font(txt.Fo nt, SDR.FontStyle.B old);
SDR.SizeF size = g.MeasureString (txt.Text, fnt);
txt.Width = SYS.Convert.ToI nt32(size.Width );
txt.Height = SYS.Convert.ToI nt32(size.Heigh t);

Thank you.
Kalvin

Jun 22 '06 #1
1 2850
Hi,

You need to make it a little bigger than the text itself.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ramhog" <ka*********@ng c.com> wrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
Hello all,
I am trying to resize a textbox to exactly fit the contents. The
method I am using gets it close but it is just a little bit too small.
Could someone tell me where I am going wrong here please?

/* SYSTEM GENERATED FOR THE TEXTBOX */
//
// txt
//
this.txt.Border Style = System.Windows. Forms.BorderSty le.None;
this.txt.Font = new System.Drawing. Font("Microsoft Sans Serif", 8.25F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.txt.Locati on = new System.Drawing. Point(72, 48);
this.txt.MaxLen gth = 100;
this.txt.Name = "txt";
this.txt.Size = new System.Drawing. Size(288, 13);
this.txt.TabInd ex = 2;
this.txt.Text = "Test String";

/* MY CODE */
SDR.Graphics g = txt.CreateGraph ics();
SDR.Font fnt = new SDR.Font(txt.Fo nt, SDR.FontStyle.B old);
SDR.SizeF size = g.MeasureString (txt.Text, fnt);
txt.Width = SYS.Convert.ToI nt32(size.Width );
txt.Height = SYS.Convert.ToI nt32(size.Heigh t);

Thank you.
Kalvin

Jun 22 '06 #2

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

Similar topics

1
1858
by: Ankan | last post by:
I have installed framework 1.1. and SP 1 on my computer. I include a textbox to my form but it can only be resized horisontally and not vertically. What is wrong? (It works fine on other components like buttons, labels...) I use Windows XP
4
3406
by: Peter Mrosek | last post by:
Hello, I have the following declaration in an header file (abbreviated version): typedef struct { unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved;
2
1318
by: DotNetJunkie | last post by:
Hi NG, I want to pass a very long string to a multilined TextBox. After doing this, I want to resize the TextBox vertically, so that the text fits into the TextBox exactly. Any ideas? I need it for a custom MessageBox. Thank you Rudi
3
3271
by: Z D | last post by:
Hello, BACKGROUND: ============== I've created a Windows User Control that contains an Image Control (among other controls). The user control handles the picture resize event. Whenever the parent that holds my user control is resized, I resize my image so that it uses the maximum available space. Note: It takes about 2 seconds to regenerate the
3
1816
by: kemal asad | last post by:
i have a vb project with vs.net i added a textbox to my form but i can not resize it in the designer view. what's going on? anything i should be checking? Thanks. Kemal
2
3289
by: avanti | last post by:
Hi, I have a multiline textbox in my application. It starts out as a single line textbox. I want it to increase in height to accomodate another line at runtime if the user input exceeds it's width. Can this be done? I have set the multiline and wordwrap properties to be true.
10
2484
by: garyusenet | last post by:
I have a multiline textbox. The size of the text box should be 75 characters wide, and 5 lines in height like this: - <---75 characters--> <---75 characters--> <---75 characters--> <---75 characters--> <---75 characters-->
4
5662
by: DeanJo | last post by:
I am trying to develop a resize module i can include on my pages that calculates the size of input fields based on the screen resolution... I can already detect the screen resolution, and i have the width / height multiplier for every resolution i need to support... my problem is this... I want the include file to be totally universal so heres my plan I will use CSS styles to set the current text box size... i want the javascript to then...
7
2912
by: robert.waters | last post by:
I have an Access database frontend linked via ODBC to a large (gigabytes) mysql database. I need to view a large amount of data in a a textbox (variable up to 300K), but I receive a 'there isnt enough memory' error whenever I scroll past N number of bytes in a textbox that has been filled with a lot of data. I am not sure what N is, but for a large chunk of data it occurs at about the halfway scroll, and smaller chunks might not throw...
0
9734
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...
1
10408
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9211
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7673
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
6895
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
5561
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
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.