最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# 實(shí)現(xiàn)簡(jiǎn)單打印的實(shí)例代碼

 更新時(shí)間:2013年03月07日 10:51:20   作者:  
C# 實(shí)現(xiàn)簡(jiǎn)單打印的實(shí)例代碼,需要的朋友可以參考一下

主窗體代碼如下:

復(fù)制代碼 代碼如下:

public partial class PrintFileForm : Form
    {
        public PrintFileForm()
        {
            InitializeComponent();
            PrintFile prinFile = new PrintFile();
            prinFile.Print();
        }
    }

打印文件類如下:

復(fù)制代碼 代碼如下:

class PrintFile
    {
        StreamReader sr = null;
        Font printFont = new Font("宋體", 12);
        public void Print()
        {
            try
            {
                sr = new StreamReader(@"F:\Temp.txt");
                try
                {
                    PrintDocument printDoc = new PrintDocument();
                    printDoc.PrintPage += printDoc_PrintPage;
                    printDoc.Print();
                }
                finally
                {
                    sr.Close();
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }

        void printDoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            string line = null;
            //設(shè)置一頁(yè)的行數(shù)=打印區(qū)域的高度除以字體高度.
            float pageLine = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
            //循環(huán)打印每一行
            for (int count = 0; count < pageLine && ((line=sr.ReadLine())!=null); count++)
            {
                float singleLine=e.MarginBounds.Top+(count*printFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(line, printFont, Brushes.Black, e.MarginBounds.Left, singleLine);
            }
            //判斷是否繼續(xù)打印
            if (line != null)
                e.HasMorePages = true;
            else
                e.HasMorePages = false;

        }
    }

相關(guān)文章

最新評(píng)論

金昌市| 罗江县| 磐安县| 平武县| 江西省| 长顺县| 江永县| 海安县| 丰城市| 竹溪县| 夹江县| 丹巴县| 丹东市| 铁岭市| 开封市| 茶陵县| 海兴县| 和平县| 邯郸县| 景泰县| 纳雍县| 柞水县| 曲水县| 江都市| 兴文县| 宁晋县| 临海市| 科尔| 阿城市| 沙坪坝区| 南和县| 镇巴县| 石嘴山市| 阿拉善右旗| 元朗区| 无锡市| 青岛市| 油尖旺区| 湖北省| 达拉特旗| 育儿|