{ // Get the string to be displayed string title = GetTheString()
// Returns the updated text for the specified column string newText = AdjustTextForDisplay(title
// Set the text including the tooltip when necessary e
string AdjustTextForDisplay(string text
{ // Calculate the dimensions of the text with the current font SizeF textSize = MeasureString(text
// Compare the size with the column
{ // Get the exceeding pixels int delta = (int) (textSize
// Calculate the average width of the characters (approx)
int avgCharWidth = (int) (textSize
// Calculate the number of chars to trim to stay in the fixed width (approx)
int chrToTrim = (int) (delta/avgCharWidth)
// Get the proper substring + the ellipsis // Trim
// Format to add a tooltip string fmt =
From:http://tw.wingwit.com/Article/program/net/201311/12632.html