Click here to Skip to main content
15,884,099 members
Home / Discussions / C#
   

C#

 
GeneralRe: Which one is better, forcing an enabled=true at each call or check it with an if statement? Pin
freakyit25-Sep-09 7:05
freakyit25-Sep-09 7:05 
GeneralRe: Which one is better, forcing an enabled=true at each call or check it with an if statement? Pin
PIEBALDconsult25-Sep-09 7:20
mvePIEBALDconsult25-Sep-09 7:20 
QuestionProblems with ID Automation Pin
Qendro25-Sep-09 2:40
Qendro25-Sep-09 2:40 
GeneralRe: Problems with ID Automation Pin
musefan25-Sep-09 2:56
musefan25-Sep-09 2:56 
GeneralRe: Problems with ID Automation Pin
Qendro25-Sep-09 3:04
Qendro25-Sep-09 3:04 
QuestionPrinting multiple font sizes on the same page... Pin
jameschristianii25-Sep-09 2:37
jameschristianii25-Sep-09 2:37 
AnswerRe: Printing multiple font sizes on the same page... Pin
musefan25-Sep-09 2:54
musefan25-Sep-09 2:54 
GeneralRe: Printing multiple font sizes on the same page... Pin
jameschristianii25-Sep-09 3:07
jameschristianii25-Sep-09 3:07 
Thank you for your quick reply.
ReceiptPrint is my subclass that inherits from PrintDocument.
I can draw whatever I want also, the problem is I need to utilize the class in a way that I can send multiple strings with various font sizes, then print all of them.

When I have attempted this, it only prints in one font size.

Here is the class for you to peek at:

class ReceiptPrint : PrintDocument
    {
        #region  Property Variables
        /// <summary>
        /// Property variable for the Font the user wishes to use
        /// </summary>
        /// <remarks></remarks>
        private Font _font;

        /// <summary>
        /// Property variable for the text to be printed
        /// </summary>
        /// <remarks></remarks>
        private string _text;
        #endregion

        #region  Class Properties
        /// <summary>
        /// Property to hold the text that is to be printed
        /// </summary>
        /// <value></value>
        /// <returns>A string</returns>
        /// <remarks></remarks>
        public string TextToPrint
        {
            get { return _text; }
            set { _text = value; }
        }

        /// <summary>
        /// Property to hold the font the users wishes to use
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public Font PrinterFont
        {
            // Allows the user to override the default font
            get { return _font; }
            set { _font = value; }
        }
        #endregion

        #region Static Local Variables
        /// <summary>
        /// Static variable to hold the current character
        /// we're currently dealing with.
        /// </summary>
        static int curChar;
        #endregion

        #region  Class Constructors 
        /// <summary>
        /// Empty constructor
        /// </summary>
        /// <remarks></remarks>
        public ReceiptPrint() : base()
        {
            //Set the file stream
            //Instantiate out Text property to an empty string
            _text = string.Empty;
        }

        /// <summary>
        /// Constructor to initialize our printing object
        /// and the text it's supposed to be printing
        /// </summary>
        /// <param name=str>Text that will be printed</param>
        /// <remarks></remarks>
        public ReceiptPrint(string str) : base()
        {
            //Set the file stream
            //Set our Text property value
            _text = str;
        }
        #endregion

        #region  OnBeginPrint
        /// <summary>
        /// Override the default OnBeginPrint method of the PrintDocument Object
        /// </summary>
        /// <param name=e></param>
        /// <remarks></remarks>
        protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
        {
            // Run base code
            base.OnBeginPrint(e);

            //Check to see if the user provided a font
            //if they didn't then we default to Times New Roman
            if (_font == null)
            {
                //Create the font we need
                _font = new Font("Arial", 10);
            }
        }
        #endregion

        #region  OnPrintPage
        /// <summary>
        /// Override the default OnPrintPage method of the PrintDocument
        /// </summary>
        /// <param name=e></param>
        /// <remarks>This provides the print logic for our document</remarks>
        protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
        {
            // Run base code
            base.OnPrintPage(e);

            //Declare local variables needed
            
            int printHeight;
            int printWidth;
            int leftMargin;
            int rightMargin;
            Int32 lines;
            Int32 chars;

            //Set print area size and margins
            {
                printHeight = base.DefaultPageSettings.PaperSize.Height - base.DefaultPageSettings.Margins.Top - base.DefaultPageSettings.Margins.Bottom;
                printWidth = base.DefaultPageSettings.PaperSize.Width - base.DefaultPageSettings.Margins.Left - 0;
                leftMargin = base.DefaultPageSettings.Margins.Left = 0;  //X
                rightMargin = base.DefaultPageSettings.Margins.Top = 0;  //Y
            }

            //Check if the user selected to print in Landscape mode
            //if they did then we need to swap height/width parameters
            if (base.DefaultPageSettings.Landscape)
            {
                int tmp;
                tmp = printHeight;
                printHeight = printWidth;
                printWidth = tmp;
            }

            //Now we need to determine the total number of lines
            //we're going to be printing
            Int32 numLines = (int)printHeight / PrinterFont.Height;

            //Create a rectangle printing are for our document
            RectangleF printArea = new RectangleF(leftMargin, rightMargin, printWidth, printHeight);

            //Use the StringFormat class for the text layout of our document
            StringFormat format = new StringFormat(StringFormatFlags.LineLimit);

            //Fit as many characters as we can into the print area      

            e.Graphics.MeasureString(_text, PrinterFont, new SizeF(printWidth, printHeight), format, out chars, out lines);

            //Print the page
            e.Graphics.DrawString(_text, PrinterFont, Brushes.Black, printArea, format);

            //Increase current char count
            curChar += chars;

            //Detemine if there is more text to print, if
            //there is the tell the printer there is more coming
            /*if (curChar < _text.Length)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
                curChar = 0;
            }*/
            e.HasMorePages = false;
        }

        #endregion

        #region  RemoveZeros 
        /// <summary>
        /// Function to replace any zeros in the size to a 1
        /// Zero's will mess up the printing area
        /// </summary>
        /// <param name=value>Value to check</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public int RemoveZeros(int value)
        {
            //Check the value passed into the function,
            //if the value is a 0 (zero) then return a 1,
            //otherwise return the value passed in
            switch (value)
            {
                case 0:
                    return 1;
                default:
                    return value;
            }
        }
        #endregion


    }

GeneralRe: Printing multiple font sizes on the same page... Pin
musefan25-Sep-09 4:24
musefan25-Sep-09 4:24 
AnswerRe: Printing multiple font sizes on the same page... Pin
Dave Kreskowiak25-Sep-09 4:27
mveDave Kreskowiak25-Sep-09 4:27 
GeneralRe: Printing multiple font sizes on the same page... Pin
jameschristianii25-Sep-09 4:32
jameschristianii25-Sep-09 4:32 
GeneralRe: Printing multiple font sizes on the same page... Pin
Dave Kreskowiak25-Sep-09 5:19
mveDave Kreskowiak25-Sep-09 5:19 
GeneralRe: Printing multiple font sizes on the same page... Pin
jameschristianii25-Sep-09 5:51
jameschristianii25-Sep-09 5:51 
AnswerRe: Printing multiple font sizes on the same page... Pin
jameschristianii25-Sep-09 17:44
jameschristianii25-Sep-09 17:44 
AnswerRe: Printing multiple font sizes on the same page... Pin
jameschristianii26-Sep-09 5:30
jameschristianii26-Sep-09 5:30 
Questionsingle User single login Pin
Shalini_U25-Sep-09 2:37
Shalini_U25-Sep-09 2:37 
AnswerRe: single User single login Pin
musefan25-Sep-09 2:47
musefan25-Sep-09 2:47 
GeneralRe: single User single login Pin
Shalini_U25-Sep-09 3:16
Shalini_U25-Sep-09 3:16 
GeneralRe: single User single login Pin
Dave Kreskowiak25-Sep-09 4:20
mveDave Kreskowiak25-Sep-09 4:20 
GeneralRe: single User single login Pin
musefan25-Sep-09 4:28
musefan25-Sep-09 4:28 
QuestionUpload data to Amibroker? Pin
$uresh $hanmugam25-Sep-09 2:32
$uresh $hanmugam25-Sep-09 2:32 
QuestionDataTableColumn.AutoIncrementSeed value Pin
Doktor25-Sep-09 0:13
Doktor25-Sep-09 0:13 
AnswerRe: DataTableColumn.AutoIncrementSeed value Pin
S.Dhanasekaran25-Sep-09 1:04
S.Dhanasekaran25-Sep-09 1:04 
GeneralRe: DataTableColumn.AutoIncrementSeed value Pin
Doktor25-Sep-09 1:15
Doktor25-Sep-09 1:15 
AnswerRe: DataTableColumn.AutoIncrementSeed value Pin
Dave Kreskowiak25-Sep-09 3:59
mveDave Kreskowiak25-Sep-09 3:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.