问题
I want to print some text like this.
This is how i want to print the text.
the code i am using is
private void button3_Click(object sender, EventArgs e)
{
stringToPrint = "This is how i want to print the text";
printFont = new Font("Times New Roman", 10);
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
try
{
pd.Print();
}
catch (Exception e)
{
}
}
void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
int charactersOnPage = 0;
int linesPerPage = 0;
ev.Graphics.MeasureString(stringToPrint, printFont,
ev.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
ev.Graphics.DrawString(stringToPrint, printFont, Brushes.Black,
ev.MarginBounds, StringFormat.GenericTypographic);
stringToPrint = stringToPrint.Substring(charactersOnPage);
ev.HasMorePages = (stringToPrint.Length > 0);
}
I want to change the Font from regular to bold or give an Underline for some specific words in the string.
And if there is another Better way to do this job then please tell me i'll change my code. Please Help me Out! :)
回答1:
You can try:
printFont = new Font("Arial", 24,FontStyle.Bold);
ThangNguyen
来源:https://stackoverflow.com/questions/18308324/c-sharp-printing-with-font-styles