0

I am trying to print out items I have saved. Each item contains a id number (ex. 34534), description( ex. book) and a barcode representation of the id number. My problem is that the barcode does not stay right below the id number. I would like for it to be in the next line or even be able to group it all in a rectangle, like you would normally see on a book/etc.

Can anyone offer suggestions or point me in the right direction?

private void uxPrintAll_Click(object sender, EventArgs e)
        {
            string result = "", result2 = "";

            printItemsList = storage.GetList();
            
            // Builds string to be printed
            for (int i = 0; i < printItemsList.Count; i++)
            {
                // Description and id number
                result += "Description: " + printItemsList[i].Description + "\n" + "UPC Code: " + printItemsList[i].ID + "\n\n\n\n";
                // id number used to be changed into barcode font
                result2 += "\n" + printItemsList[i].ID + "\n";
            }

            PrintDocument p = new PrintDocument();

            p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
            {
                e1.Graphics.DrawString(result, new Font("Times New Roman", 12), new SolidBrush(Color.Black), 
                    new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
                e1.Graphics.DrawString(result2, new Font(pfc.Families[0], 30), new SolidBrush(Color.Black),
                    new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
            };
            try
            {
                p.Print();
            }
            catch (Exception ex)
            {
                throw new Exception("Exception Occured While Printing", ex);
            }
        }
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by nick.crane
0

You probably need to look at using the DrawString overloads that have a StringFormat parameter.
This allows you to control the alignment of text within a rectangle (left,center,right; top, middle, bottom).:)

[Edit]
I find that using the StringFormat.GenericTypographic format as a base,
then adjusting the alignment properties appropriately works best.

A word of warning. It is not as clear as left, center, right.
The properties of the StringFormat that control alignment are LineAlignment and Alignment.
Both use the StringAlignment enum that has values Near, Center, Far.:confused:

Experimentation is the best way to understand how the alignment properties effects the output.

Edited by nick.crane: Added details

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.