georgepatotk Posted February 14, 2005 Posted February 14, 2005 Happy Chinese New Year... I am using a textbox in my winform. The default size of the font is 12 and the size of the textbox is 224,64. I have thousands of records to be shown in this textbox, one by one. I have this problem where sometimes the records are too long to fit into the textbox. Means 224,64 is not enough. Since i can't size of the textbox is fixed, so, I would like to change the font size accordingly. I wish to do something likee this While (it is not enough) TextBox1.Font = New Font("Microsoft Sans Serif", TextBox1.Font.Size - 1) End While so, anyone could help me on this? Please.. Quote George C.K. Low
Leaders snarfblam Posted February 14, 2005 Leaders Posted February 14, 2005 Are you showing one record at a time in one textbox at a time? Anyways, I would recommend using the System.Drawing.Graphics.MeasureString function to see if the text will fit in the box, and if it doesnt then... you can try decreasing the fontsize by one until it fits (provided that you have a point at which it will give up; it would be pointless to show your data at a size 1 font and this method may be somewhat error prone). If you absolutely can not increase the size of your textbox perhaps you can set the record text to a tool tip so that the user can place the mouse over the textbox and the record will pop up in a tooltip. Quote [sIGPIC]e[/sIGPIC]
georgepatotk Posted February 14, 2005 Author Posted February 14, 2005 Are you showing one record at a time in one textbox at a time? Anyways, I would recommend using the System.Drawing.Graphics.MeasureString function to see if the text will fit in the box, and if it doesnt then... you can try decreasing the fontsize by one until it fits (provided that you have a point at which it will give up; it would be pointless to show your data at a size 1 font and this method may be somewhat error prone). If you absolutely can not increase the size of your textbox perhaps you can set the record text to a tool tip so that the user can place the mouse over the textbox and the record will pop up in a tooltip. Good idea for the tooltip. and for the System.Drawing.Graphics.MeasureString, I don't really know how to use this. Can explain more to me? By the way, I will search it fhru net as well.. Quote George C.K. Low
georgepatotk Posted February 14, 2005 Author Posted February 14, 2005 Can show me a simple example for System.Drawing.Graphics.MeasureString? Just a simple example is more than enough. I just want to get started with it. Quote George C.K. Low
Leaders snarfblam Posted February 14, 2005 Leaders Posted February 14, 2005 its really pretty simple. Assuming your textbox is named txtRecord... Dim gTextBox As Graphics = txtRecord.CreateGraphics() If gTextBox.MeasureString("", txtRecord.Font).Width > TextBox.Width Then 'Do what you need to do End If [/Code] Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.