SoFunction
Updated on 2025-03-01

C# implements simple printing instance code


class PrintFile
    {
        StreamReader sr = null;
Font printFont = new Font("Song style", 12);
        public void Print()
        {
            try
            {
                sr = new StreamReader(@"F:\");
                try
                {
                    PrintDocument printDoc = new PrintDocument();
                    += printDoc_PrintPage;
                    ();
                }
                finally
                {
                    ();
                }

            }
            catch (Exception ex)
            {
                ();
            }

        }

        void printDoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            string line = null;
//Set the number of lines of a page = the height of the print area divided by the font height.
            float pageLine = / ();
//Loop printing of each line
            for (int count = 0; count < pageLine && ((line=())!=null); count++)
            {
                float singleLine=+(count*());
                (line, printFont, , , singleLine);
            }
//Judge whether to continue printing
            if (line != null)
                = true;
            else
                = false;

        }
    }