Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed a project on retail management system. I have used POS Printer and
I don't know a code use for print bill using POS Printer using WPF (C#) Technology.
Please give me idea how it done.
C#
// Print Event
		private void miPrint_Click(object sender, System.EventArgs e)
		{
			if (printDialog1.ShowDialog() == DialogResult.OK)
			{
               // printDocument1.DefaultPageSettings.PaperSize.Width = 9000;
				printDocument1.Print();
			}
		}
		
		// OnBeginPrint 
		private void OnBeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
		{
			char[] param = {'\n'};
            PrinterSettings p = new PrinterSettings();
            PaperSize ps = new PaperSize ("Custom",9000,90000);
            printDocument1.DefaultPageSettings.PaperSize = ps;

			if (printDialog1.PrinterSettings.PrintRange == PrintRange.Selection)
			{
				lines = richTextBox1.SelectedText.Split(param);
			}
			else
			{
				lines = richTextBox1.Text.Split(param);
			}
			
			int i = 0;
			char[] trimParam = {'\r'};
			foreach (string s in lines)
			{
				lines[i++] = s.TrimEnd(trimParam);
			}
		}
        // OnPrintPage
		private void OnPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
		{
			int x = e.MarginBounds.Left;
			int y = e.MarginBounds.Top;
			Brush brush = new SolidBrush(richTextBox1.ForeColor);
			
			while (linesPrinted < lines.Length)
			{
				e.Graphics.DrawString (lines[linesPrinted++],
					richTextBox1.Font, brush, x, y);
				y += 15;
				if (y >= e.MarginBounds.Bottom)
				{
					e.HasMorePages = true;
					return;
				}
			}
			
			linesPrinted = 0;
			e.HasMorePages = false;
		}
        // Page Setup
		private void miSetup_Click(object sender, System.EventArgs e)
		{
			// Call Dialog Box
			pageSetupDialog1.ShowDialog();
		}
        // Print Preview
		private void miPreview_Click(object sender, System.EventArgs e)
		{
			// Call Dialog Box
			printPreviewDialog1.ShowDialog();
		}


Thanks in advance.....
Posted
Updated 3-Dec-12 21:10pm
v3
Comments
Expert Coming 4-Dec-12 0:47am    
Show us the code you have now that isn't working. Also explain what isn't working for you.
Programm3r 4-Dec-12 0:55am    
Hi - what type of printer is it?
Programm3r 4-Dec-12 2:19am    
Hi - please have a look at the following threads:

http://go4answers.webhost4life.com/Example/pos-bill-printing-opos-6449.aspx
http://www.yortondotnet.com/2009/07/better-way-to-print-receipts.html

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900