while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null)) { List<string> str = WrapText(line, e1.MarginBounds.Width-e1.MarginBounds.X-e1.MarginBounds.Left, fontDialog1.Font.FontFamily.Name, fontDialog1.Font.SizeInPoints); for (int j = 0; j < str.Count; j++) { yPos = topMargin + (count * fontDialog1.Font.GetHeight(e1.Graphics)); e1.Graphics.DrawString(str[j], fontDialog1.Font, myBrush, leftMargin, yPos, new StringFormat()); count++; } } static List<string> WrapText(string text, double pixels, string fontFamily, float emSize) { List<string> wrappedLines = new List<string>(); StringBuilder actualLine = new StringBuilder(); double actualWidth = 0; foreach (var item in text) { actualLine.Append(item); FormattedText formatted = new FormattedText(actualLine.ToString(), CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface(fontFamily), emSize, System.Windows.Media.Brushes.Green); actualWidth = formatted.Width; if (actualWidth > pixels-50) { wrappedLines.Add(actualLine.ToString()); wrappedLines.Add("\n"); actualLine.Clear(); actualWidth = 0; } } if (actualLine.Length > 0) { wrappedLines.Add(actualLine.ToString()); wrappedLines.Add("\n"); } return wrappedLines;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)