作者autumnplume ( )
看板C_Sharp
标题[问题] 列印不同字型与颜色的问题
时间Mon Feb 14 23:12:19 2011
我初学CSharp, 最近在练习写一个记事本的程式,
遇到设置列印功能上的一个问题,
From MSDN
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
while(count < linesPerPage &&
((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
//
//以下略
//
}
其中printFont被指定成Arial, 10,
而使用Graphics.DrawString又只能把颜色设成单一色,
我试图用this.richTextBox.SelectionFont,
与this.richTextBox.SelectionColor去处理,
compiler可以过, 印也能印,
不过当我richTextBox中的文字, 同时使用不同的字型与颜色,
印出来整页全部只会使用游标所在的字型与颜色,
已经找了一整天了还是找不到对於这两个控制项的任何答案,
不知道是否有人能给我一个方向?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.69.103.245