| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 810 人关注过本帖
标题:C#打印问题
只看楼主 加入收藏
kenshin5868
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-7-31
收藏
 问题点数:0 回复次数:1 
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;
            
        }
我想在打印中将表格中的单元格设置为空两格,而不是居中对齐或左对齐。请教高手指点迷津哈!!!!
搜索更多相关主题的帖子: 打印 
2008-08-15 09:41
kenshin5868
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-7-31
收藏
得分:0 
是单元格中的内容空两格打印,而不是单元格本身喔,打印出来的表跟EXCEL差不多的。。
2008-08-15 09:44
快速回复:C#打印问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028420 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved