By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Textbox resize problem

P: n/a
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.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txt.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.txt.Location = new System.Drawing.Point(72, 48);
this.txt.MaxLength = 100;
this.txt.Name = "txt";
this.txt.Size = new System.Drawing.Size(288, 13);
this.txt.TabIndex = 2;
this.txt.Text = "Test String";

/* MY CODE */
SDR.Graphics g = txt.CreateGraphics();
SDR.Font fnt = new SDR.Font(txt.Font, SDR.FontStyle.Bold);
SDR.SizeF size = g.MeasureString(txt.Text, fnt);
txt.Width = SYS.Convert.ToInt32(size.Width);
txt.Height = SYS.Convert.ToInt32(size.Height);

Thank you.
Kalvin

Jun 22 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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*********@ngc.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.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.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txt.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.txt.Location = new System.Drawing.Point(72, 48);
this.txt.MaxLength = 100;
this.txt.Name = "txt";
this.txt.Size = new System.Drawing.Size(288, 13);
this.txt.TabIndex = 2;
this.txt.Text = "Test String";

/* MY CODE */
SDR.Graphics g = txt.CreateGraphics();
SDR.Font fnt = new SDR.Font(txt.Font, SDR.FontStyle.Bold);
SDR.SizeF size = g.MeasureString(txt.Text, fnt);
txt.Width = SYS.Convert.ToInt32(size.Width);
txt.Height = SYS.Convert.ToInt32(size.Height);

Thank you.
Kalvin

Jun 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.