void RenderAllText(Graphics g, System.Drawing.Rectangle r) { if (ListView.Columns.Count == 0) { return; } // title OLVColumn titleColumn = ListView.GetColumn(0); Debug.Assert(titleColumn.IsPrimary()); string titleText = titleColumn.GetStringValue(RowObject); bool wordWrap = r.Height < 20 ? false : titleColumn.CheckWordWrap(); Size titleSize = CalculateTextSize(g, titleText, r.Width, wordWrap); titleSize.Height = Math.Min(titleSize.Height, r.Height); DrawText(g, r, titleText, GetForegroundColor(), titleColumn.CheckWordWrap()); // description if (ListView.Columns.Count > 1) { OLVColumn descColumn = ListView.GetColumn(1); string descText = descColumn.GetStringValue(RowObject); if (!string.IsNullOrEmpty(descText)) { Size descSize = CalculateTextSize(g, descText, r.Width, descColumn.WordWrap); Size oneLineSize = CalculateTextSize(g, "Test", Int32.MaxValue, false); for (int h = descSize.Height; h >= 0; h -= oneLineSize.Height) { if (h > 0 && titleSize.Height + h <= r.Height) { var rect = r; rect.Y += titleSize.Height; rect.Height -= titleSize.Height; DrawText(g, rect, descText, GetDescriptionForegroundColor(), true /*descColumn.WordWrap*/); return; } } // draw in one line with title var rect2 = r; rect2.X += titleSize.Width + 5; rect2.Width -= titleSize.Width + 5; DrawText(g, rect2, descText, GetDescriptionForegroundColor(), false); } } }
//Size GetTileTextSize( Graphics g, Size r ) //{ // int height = 0; // for( int i = 0; i < ListView.Columns.Count; i++ ) // { // OLVColumn column = ListView.GetColumn( i ); // if( column.IsPrimary() || column.IsTileViewColumn ) // { // string txt = column.GetStringValue( RowObject ); // if( string.IsNullOrEmpty( txt ) ) // break; // Size size = CalculateTextSize( g, txt, r.Width, column.CheckWordWrap() ); // size.Height = Math.Min( size.Height, r.Height ); // if( height + size.Height > r.Height ) // break; // height += size.Height + 2; // } // } // return new Size( r.Width, height ); //} Size GetAllTextSize(Graphics g, Size r, out bool ellipsis) { ellipsis = false; int totalHeight = 0; // title OLVColumn titleColumn = ListView.GetColumn(0); Debug.Assert(titleColumn.IsPrimary()); string titleText = titleColumn.GetStringValue(RowObject); bool wordWrap = r.Height < 20 ? false : titleColumn.CheckWordWrap(); Size titleSize = CalculateTextSize(g, titleText, r.Width, wordWrap); titleSize.Height = Math.Min(titleSize.Height, r.Height); totalHeight += titleSize.Height + 2; // description if (ListView.Columns.Count > 1) { OLVColumn descColumn = ListView.GetColumn(1); string descText = descColumn.GetStringValue(RowObject); if (!string.IsNullOrEmpty(descText)) { Size descSize = CalculateTextSize(g, descText, r.Width, true); Size oneLineSize = CalculateTextSize(g, "Test", Int32.MaxValue, false); // we can t use Font.Height for (int h = descSize.Height; h >= 0; h -= oneLineSize.Height) { if (totalHeight + h <= r.Height) { ellipsis = descSize.Height > (h != 0 ? h : oneLineSize.Height); //descColumn.WordWrap = true; return(new Size(r.Width, totalHeight + h)); } } } } return(new Size(r.Width, totalHeight)); }