All content of the new home page of 9CBS is currently manually updated, the workload is very powerful, and one is to cut the title of the article so that there is no super long resolution.
Originally, the title width can be controlled in the program. If you automatically truncate and use Tooltip's form, the full title is displayed, but because the font used by the 9CBS home page is TaHoma 12px, the English font is not equivalent, so it is difficult to determine the width.
I have been doing my brands to solve the way. Yesterday, I have been suggeting the opinion on page maintenance work. Therefore, some columns will need to be automatically updated, so the title requires automatic truncation.
So I need to get the size of the string, pixel unit.
In the .NET's System.drawing space, the Graphics object provides a method that can achieve this: MeasureString (), with the overload information, see MSDN.
The code segment of the obtained string length last night is as follows:
private void MainForm_Paint (object sender, System.Windows.Forms.PaintEventArgs e) {Font font = new Font ( "Tahoma", 11, GraphicsUnit.Pixel); SizeF size = e.Graphics.MeasureString (drawText, font); this. Text = size.width.toString (); E.Graphics.drawRectangle (New Pen (Color.red, 1), 0.0F, 0.0F, Size.width, Size.Height); E.Graphics.drawstring (DrawText, Font Brushes.black, new pointf (0, 0));
The width pixel value of the current feels is slightly greater than the theoretical value. Continue to improve tomorrow ~