How to count pixels
-
Hi All, I am adding a string value to listbox control. I need to set the width of listbox in runtime base on how many pixels string need it to display it within listbox. Idea is to set a width of listbox exactly the number of pixels required by string value. So, I can have perfact width each time base on string value. Any idea please help. Thanks, Asif.
A.Asif
-
Hi All, I am adding a string value to listbox control. I need to set the width of listbox in runtime base on how many pixels string need it to display it within listbox. Idea is to set a width of listbox exactly the number of pixels required by string value. So, I can have perfact width each time base on string value. Any idea please help. Thanks, Asif.
A.Asif
-
Hi All, I am adding a string value to listbox control. I need to set the width of listbox in runtime base on how many pixels string need it to display it within listbox. Idea is to set a width of listbox exactly the number of pixels required by string value. So, I can have perfact width each time base on string value. Any idea please help. Thanks, Asif.
A.Asif
TextBox tb = new TextBox(); ... Graphics g = null; try { g = tb.CreateGraphics(); SizeF result = g.MeasureString(tb.Text, tb.Font); // you may need to take into account margin, padding, or border sizes tb.Width = (int)Math.Ceiling(result.Width); } finally { if (g != null) g.Dispose(); } Jeff