Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

Kindly solve My Problem, When click on show report right side lost word broken,
C#
                 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;
Posted
Updated 4-Jul-14 5:14am
v5
Comments
Sergey Alexandrovich Kryukov 4-Jul-14 11:26am    
You did not say a word on what is that code fragment about...
—SA
BacchusBeale 7-Jul-14 0:51am    
I think your question means to say: "How to wrap text without losing or breaking words". Correct?
chellapandi160 7-Jul-14 1:59am    
Yes, Mr.BacchusBeale.

Exactly,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900