protected int CalculateHeight(Graphics g) { System.Windows.Forms.TextFormatFlags textFormatFlags = this.TextFormatFlags; float num = 0f; for (int i = 0; i < this.ListView.Columns.Count; i++) { OLVColumn column = this.ListView.GetColumn(i); Font font = this.CalculateFont(column); if (this.WordWrap) { Rectangle itemRect = this.GetItemRect(i); itemRect.Width -= 6; if (this.HasNonThemedSortIndicator(column)) { itemRect.Width -= 0x10; } SizeF ef = (SizeF)TextRenderer.MeasureText(g, column.Text, font, new Size(itemRect.Width, 100), textFormatFlags); num = Math.Max(num, ef.Height); } else { num = Math.Max(num, (float)font.Height); } } return(7 + ((int)num)); }
/// <summary> /// /// </summary> /// <param name="Alignment"></param> /// <param name="RightToleft"></param> /// <returns></returns> internal static System.Windows.Forms.TextFormatFlags GetTextFormatFlags( ContentAlignment Alignment, bool RightToleft) { System.Windows.Forms.TextFormatFlags flags = System.Windows.Forms.TextFormatFlags.WordBreak | System.Windows.Forms.TextFormatFlags.SingleLine; if (RightToleft) { flags |= System.Windows.Forms.TextFormatFlags.RightToLeft | System.Windows.Forms.TextFormatFlags.Right; } switch (Alignment) { case ContentAlignment.BottomCenter: flags |= System.Windows.Forms.TextFormatFlags.Bottom | System.Windows.Forms.TextFormatFlags.HorizontalCenter; break; case ContentAlignment.BottomLeft: flags |= System.Windows.Forms.TextFormatFlags.Bottom | System.Windows.Forms.TextFormatFlags.Left; break; case ContentAlignment.BottomRight: flags |= System.Windows.Forms.TextFormatFlags.Bottom | System.Windows.Forms.TextFormatFlags.Right; break; case ContentAlignment.MiddleCenter: flags |= System.Windows.Forms.TextFormatFlags.HorizontalCenter | System.Windows.Forms.TextFormatFlags.VerticalCenter; break; case ContentAlignment.MiddleLeft: flags |= System.Windows.Forms.TextFormatFlags.VerticalCenter | System.Windows.Forms.TextFormatFlags.Left; break; case ContentAlignment.MiddleRight: flags |= System.Windows.Forms.TextFormatFlags.VerticalCenter | System.Windows.Forms.TextFormatFlags.Right; break; case ContentAlignment.TopCenter: flags |= System.Windows.Forms.TextFormatFlags.Top | System.Windows.Forms.TextFormatFlags.HorizontalCenter; break; case ContentAlignment.TopLeft: flags |= System.Windows.Forms.TextFormatFlags.Top | System.Windows.Forms.TextFormatFlags.Left; break; case ContentAlignment.TopRight: flags |= System.Windows.Forms.TextFormatFlags.Top | System.Windows.Forms.TextFormatFlags.Right; break; } return(flags); }
void SetStringFormat() { textFormat = swf.TextFormatFlags.Default; switch (Wrap) { case WrapMode.None: textFormat |= swf.TextFormatFlags.SingleLine; break; case WrapMode.Word: textFormat |= swf.TextFormatFlags.WordBreak; break; case WrapMode.Character: break; } switch (TextAlignment) { case TextAlignment.Left: textFormat |= swf.TextFormatFlags.Left; break; case TextAlignment.Right: textFormat |= swf.TextFormatFlags.Right; break; case TextAlignment.Center: textFormat |= swf.TextFormatFlags.HorizontalCenter; break; } switch (VerticalAlignment) { case VerticalAlignment.Top: case VerticalAlignment.Stretch: textFormat |= swf.TextFormatFlags.Top; break; case VerticalAlignment.Bottom: textFormat |= swf.TextFormatFlags.Bottom; break; case VerticalAlignment.Center: textFormat |= swf.TextFormatFlags.VerticalCenter; break; } ClearSize(); }
void SetStringFormat() { textFormat = swf.TextFormatFlags.Default; switch (Wrap) { case WrapMode.None: textFormat |= swf.TextFormatFlags.SingleLine; break; case WrapMode.Word: textFormat |= swf.TextFormatFlags.WordBreak; break; case WrapMode.Character: break; } switch (HorizontalAlign) { case HorizontalAlign.Left: textFormat |= swf.TextFormatFlags.Left; break; case HorizontalAlign.Right: textFormat |= swf.TextFormatFlags.Right; break; case HorizontalAlign.Center: textFormat |= swf.TextFormatFlags.HorizontalCenter; break; } switch (VerticalAlign) { case VerticalAlign.Top: textFormat |= swf.TextFormatFlags.Top; break; case VerticalAlign.Bottom: textFormat |= swf.TextFormatFlags.Bottom; break; case VerticalAlign.Middle: textFormat |= swf.TextFormatFlags.VerticalCenter; break; } }
private static string TruncatePathForDisplay(string text, int Width, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags FormatFlags) { var result = string.Copy(text); TextRenderer.MeasureText(result, font, new System.Drawing.Size(Width, 0), FormatFlags | TextFormatFlags.ModifyString); return(result); }
protected void CustomDrawHeaderCell(Graphics g, int columnIndex, int itemState) { Rectangle itemRect = this.GetItemRect(columnIndex); OLVColumn column = this.ListView.GetColumn(columnIndex); int columnIndexUnderCursor = this.ColumnIndexUnderCursor; if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal)) { int part = 1; if ((columnIndex == 0) && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemLeft.Normal)) { part = 2; } if ((columnIndex == (this.ListView.Columns.Count - 1)) && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemRight.Normal)) { part = 3; } int state = 1; if ((itemState & 1) == 1) { state = 3; } else if (columnIndex == this.ColumnIndexUnderCursor) { state = 2; } new VisualStyleRenderer("HEADER", part, state).DrawBackground(g, itemRect); } else { ControlPaint.DrawBorder3D(g, itemRect, Border3DStyle.Raised); } if (this.HasSortIndicator(column)) { if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.SortArrow.SortedUp)) { VisualStyleRenderer renderer2 = null; if (this.ListView.LastSortOrder == SortOrder.Ascending) { renderer2 = new VisualStyleRenderer(VisualStyleElement.Header.SortArrow.SortedUp); } if (this.ListView.LastSortOrder == SortOrder.Descending) { renderer2 = new VisualStyleRenderer(VisualStyleElement.Header.SortArrow.SortedDown); } if (renderer2 != null) { Size partSize = renderer2.GetPartSize(g, ThemeSizeType.True); Point location = renderer2.GetPoint(PointProperty.Offset); if ((location.X == 0) && (location.Y == 0)) { location = new Point((itemRect.X + (itemRect.Width / 2)) - (partSize.Width / 2), itemRect.Y); } renderer2.DrawBackground(g, new Rectangle(location, partSize)); } } else { Point point2 = new Point((itemRect.Right - 0x10) - 2, itemRect.Top + ((itemRect.Height - 0x10) / 2)); Point[] points = new Point[] { point2, point2, point2 }; if (this.ListView.LastSortOrder == SortOrder.Ascending) { points[0].Offset(2, 10); points[1].Offset(8, 3); points[2].Offset(14, 10); } else { points[0].Offset(2, 4); points[1].Offset(8, 10); points[2].Offset(14, 4); } g.FillPolygon(Brushes.SlateGray, points); itemRect.Width -= 0x10; } } System.Windows.Forms.TextFormatFlags textFormatFlags = this.TextFormatFlags; if (column.TextAlign == HorizontalAlignment.Center) { textFormatFlags |= System.Windows.Forms.TextFormatFlags.HorizontalCenter; } if (column.TextAlign == HorizontalAlignment.Right) { textFormatFlags |= System.Windows.Forms.TextFormatFlags.Right; } Font font = this.CalculateFont(column); Color headerForeColor = column.HeaderForeColor; if (headerForeColor.IsEmpty) { headerForeColor = this.ListView.ForeColor; } itemRect.Inflate(-3, 0); itemRect.Y -= 2; TextRenderer.DrawText(g, column.Text, font, itemRect, headerForeColor, Color.Transparent, textFormatFlags); }