C#打印问题
我想在打印中将表格中的单元格设置为空两格,而不是居中对齐或左对齐。,该如何修改呀,请教高手指点迷津哈!!!!下面是本人的一段打印设置代码(我用黑体的部分就是左对齐打印的)
private bool PrintDataGrid(Graphics g)
{
StringFormat sf = new StringFormat();
PageCounter++;
//if we want to print the grid right to left
if (bRightToLeft)
{
CurrentX = pageWidth - pageMarginRight;
sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
}
else
{
CurrentX = pageMarginLeft;
}
for (int i=CurrentRow;i<PrintGrid.Rows;i++)
{
for (int j=0;j<PrintGrid.Columns;j++)
{
//set cell alignment
[bo]switch ([/bo]PrintGrid[i,j].Alignment)
{
//left
case HorizontalAlignment.Left:
sf.Alignment = StringAlignment.Near+2;
break;
//center
case HorizontalAlignment.Center:
sf.Alignment = StringAlignment.Center;
break;
//right
case HorizontalAlignment.Right:
sf.Alignment = StringAlignment.Far;
break;
}[/bo]
//advance X according to order
if (bRightToLeft)
{
//draw the cell bounds (lines) and back color
g.FillRectangle(new SolidBrush(PrintGrid.BackColor),CurrentX - PrintGrid[i,j].Width,CurrentY,PrintGrid[i,j].Width,PrintGrid[i,j].Height);
g.DrawRectangle(new Pen(PrintGrid.LineColor),CurrentX - PrintGrid[i,j].Width,CurrentY,PrintGrid[i,j].Width,PrintGrid[i,j].Height);
//draw the cell text
g.DrawString(PrintGrid[i,j].Text,PrintGrid[i,j].Font,new SolidBrush(PrintGrid.ForeColor),new RectangleF(CurrentX - PrintGrid[i,j].Width,CurrentY,PrintGrid[i,j].Width,PrintGrid[i,j].Height),sf);
//next cell
CurrentX -=PrintGrid[i,j].Width;
}
else
{
//draw the cell bounds (lines) and back color
g.FillRectangle(new SolidBrush(PrintGrid.BackColor) ,CurrentX,CurrentY,PrintGrid[i,j].Width,PrintGrid[i,j].Height);
g.DrawRectangle(new Pen(PrintGrid.LineColor) ,CurrentX,CurrentY,PrintGrid[i,j].Width,PrintGrid[i,j].Height);
//draw the cell text
//Draw text by alignment
g.DrawString(PrintGrid[i,j].Text,PrintGrid[i,j].Font,new SolidBrush(PrintGrid.ForeColor),new RectangleF(CurrentX,CurrentY,PrintGrid[i,j].Width,PrintGrid[i,j].Height),sf);
//next cell
CurrentX +=PrintGrid[i,j].Width;
}
}
//reset to beginning
if (bRightToLeft)
{
//right align
CurrentX = pageWidth - pageMarginRight;
}
else
{
//left align
CurrentX = pageMarginLeft;
}
//advance to next row
CurrentY = CurrentY + PrintGrid[i,0].Height;
CurrentRow++;
//if we are beyond the page margin (bottom/side) then we need another page,
//return true
//if portrait is selected
if((CurrentY > pageHeight -
pageMarginBottom)&&(!pageLandscape))
{
return true;
}
//if landscape is selected
if((CurrentY > pageWidth -
pageMarginRight)&&(pageLandscape))
{
return true;
}
}
CurrentRow = 0;
return false;
}
我想在打印中将表格中的单元格设置为空两格,而不是居中对齐或左对齐。请教高手指点迷津哈!!!!