Unable to trim the string in PrintDocument
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开发者_Go百科 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();
}
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}
精彩评论