views:

25

answers:

1

I have some string to print on PrintDocument using its graphic object using following code, and I'm expecting if rectangle area in small to fit whole string it show trim it with ellipses but the trimming is not applied to the drawn string, is there any thing wrong in the code? (If draw string on windows form it works)

        PrintDocument printDocument;
        void print_PrintPage(object sender, PrintPageEventArgs e)
        {
            var g = e.Graphics;

            var rect = new Rectangle(10, 10, 50, 50);
            g.DrawRectangle(Pens.Red, rect);
            g.DrawString("Draws the specified text string at the specified position", 
                Font, Brushes.Red, 
                rect, 
                new StringFormat { Trimming = StringTrimming.EllipsisCharacter });

        }

        private void printPreviewControl_Click(object sender, EventArgs e)
        {
            printPreviewControl.Document = printDocument;
            printPreviewControl.Show();
        }
+1  A: 

I could not detect a difference between PrintPreview and drawing to a Panel with the same code.

To get the ellipses you will have to specify NoWrap though:

 new StringFormat { 
        Trimming = StringTrimming.EllipsisCharacter , 
        FormatFlags = StringFormatFlags.NoWrap}
Henk Holterman
@Henk, I do need to draw multi-line string and also need Ellipsis Character. I did find solution by setting `StringFormat` to `LineLimit`
Prashant