Results 1 to 13 of 13

Thread: Print through WinForms

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    8

    Print through WinForms

    Hello,

    I have a printer named Datecs EP-50.
    I have this code:

    Code:
    e.Graphics.DrawString("  NOTA DE PLATA",print10B,Brushes.Black,10,0);
                
                e.Graphics.DrawString(" Masa: ", print8B, Brushes.Black, 8, 35);
                e.Graphics.DrawString(label_pin.Tag.ToString(),print8B, Brushes.Black, 48, 35);
                e.Graphics.DrawString(" Data: ", print8B, Brushes.Black,8 , 50);
                int length = DateTime.Now.Day.ToString().Length + DateTime.Now.Month.ToString().Length + DateTime.Now.Year.ToString().Length + DateTime.Now.ToShortTimeString().Length;
                int length2 = " Data: ".Length + 3;
                e.Graphics.DrawString(DateTime.Now.Day+"/"+DateTime.Now.Month+"/"+DateTime.Now.Year+"  "+DateTime.Now.ToShortTimeString(), print8B, Brushes.Black, length2+length, 70);
                e.Graphics.DrawString("-----------------------------------------", new Font(dataGridView1.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10, 80);
                e.Graphics.DrawString("Produs   | Cant | Pret | Total ", print8B, Brushes.Black, 10, 110);
                int height = 0;
                int x = 10;
                
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    e.Graphics.DrawString(dataGridView1.Rows[i].Cells["DenumireProdus"].Value.ToString(), print6B, Brushes.Black, x, 130+height);
                    e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produs_cantitate"].Value.ToString(), print6B, Brushes.Black, x+70, 130 + height);
                    e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produs_pret"].Value.ToString() , print6B, Brushes.Black, x+105, 130 + height);
                    e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produsvaloare"].Value.ToString(), print6B, Brushes.Black, x + 135, 130 + height);
                    height += 20;
                    
                }
                e.Graphics.DrawString("-----------------------------------------", new Font(dataGridView1.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10,dataGridView1.Height+_maxPage+_page+46);
                e.Graphics.DrawString("Total:  " + textBox1.Text+" RON", print10B, Brushes.Black,40,dataGridView1.Height + _maxPage+20+_page+55);
    My problem is that this code only prints the header and another 7 records. After the 7-th record the printer stops printing. Why does it happening ?
    Last edited by vlasin; Jan 28th, 2012 at 01:04 PM.

  2. #2
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Re: Print through WinForms

    Hey vlasin,

    To help you better you will need to supply more code than that. Where is the code that actually prints the graphic and where is the data source?

    -jD

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    8

    Re: Print through WinForms

    Thank you for the answer... data sources are the DataGridView rows . The code above is from PrintDocument1_PrintPage(sender,e) and I call the print event after a button press. On a normal printer the result is ok but on cash register printer is printing only a few lines. The printer is called Datecs EP-50 and it really gives me some headache.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    8

    Re: Print through WinForms

    A sample of a program that the printer accepts it:

    Code:
    LPRINT CHR$ (&H1B) + “$”;
    LPRINT CHR$ (0) + CHR$ (0) + “A”;
    LPRINT CHR$ (&H1B) + “$”;
    LPRINT CHR$ (50) + CHR$ (0) + “B”;
    LPRINT CHR$ (&H1B) + “$”;
    LPRINT CHR$ (0) + CHR$ (1) + “C”;
    LPRINT CHR$ (&HA);
    LPRINT CHR$ (&H1B) + “$”;
    LPRINT CHR$ (100) + CHR$ (0) + “A”;
    LPRINT CHR$ (&H1B) + “&#165;”;
    LPRINT CHR$ (&HC2) + CHR$ (&HFF) + “B”;
    LPRINT CHR$ (&HA);
    How do i send this to the printer in C# ?

  5. #5
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Re: Print through WinForms

    Ok, well i'm assuming the Datecs EP-50 supplys print drivers you have installed onto your computer. What happens if you try and print more than 7 lines from a word document? If word can print more than 7 lines it tells me there is something wrong with either the driver or the Graphics obgject being generated.

    EDIT: Just found their SDK on their website (http://www.datecs.bg/get_file.php?so...7BFCB200B0034A). Are you using this, or standard windows drivers?

    -jD

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    8

    Re: Print through WinForms

    After 7 lines printed the EP-50 stops . I mean it is not printing the rest of the Graphics anymore. I found that SDK too and after i read the docs i realized that it is perfect for my project but the problem is that i do not know how to add the dll file to my project. I've tried to add it to the references for the project but it gave me an error.

    I assume that the drivers are installed in Windows XP because EP-50 is printing the test page from windows, but now I'm thinking that the drivers might not be up to date.
    Last edited by vlasin; Jan 29th, 2012 at 03:18 AM.

  7. #7
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Print through WinForms

    I dont think it has anything to do with drivers. If your printer can print within Windows, then so can your application.

    how many rows are there in your datagridview that you are printing?
    can you supply code in its entirety? how are you printing it? using what method? what code?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    8

    Re: Print through WinForms

    Here it is the code:

    Code:
    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                Font print10B = new Font("Lucida Console", 10, FontStyle.Bold);
                Font print8B = new Font("Arial", 9, FontStyle.Regular);
                Font print6B = new Font("Arial", 8, FontStyle.Regular);
               
                
            
                e.Graphics.DrawString("  NOTA DE PLATA",print10B,Brushes.Black,10,0);
                
                e.Graphics.DrawString(" Masa: ", print8B, Brushes.Black, 8, 35);
                e.Graphics.DrawString(label_pin.Tag.ToString(),print8B, Brushes.Black, 48, 35);
                e.Graphics.DrawString(" Data: ", print8B, Brushes.Black,8 , 50);
                int length = DateTime.Now.Day.ToString().Length + DateTime.Now.Month.ToString().Length + DateTime.Now.Year.ToString().Length + DateTime.Now.ToShortTimeString().Length;
                int length2 = " Data: ".Length + 3;
                e.Graphics.DrawString(DateTime.Now.Day+"/"+DateTime.Now.Month+"/"+DateTime.Now.Year+"  "+DateTime.Now.ToShortTimeString(), print8B, Brushes.Black, length2+length, 70);
                e.Graphics.DrawString("-----------------------------------------", new Font(dataGridView1.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10, 80);
                e.Graphics.DrawString("Produs   | Cant | Pret | Total ", print8B, Brushes.Black, 10, 110);
                int height = 0;
                int x = 10;
          
                int pozition = 0;
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        e.Graphics.DrawString(dataGridView1.Rows[i].Cells["DenumireProdus"].Value.ToString(), print6B, Brushes.Black, x, 130 + height);
                        e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produs_cantitate"].Value.ToString(), print6B, Brushes.Black, x + 70, 130 + height);
                        e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produs_pret"].Value.ToString(), print6B, Brushes.Black, x + 105, 130 + height);
                        e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produsvaloare"].Value.ToString(), print6B, Brushes.Black, x + 135, 130 + height);
                        height += 20;
                       
                    }
                    if (pozition > height)
                    {
                        pozition = height;
                    }
                    e.Graphics.DrawString("-----------------------------------------", new Font(dataGridView1.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10, dataGridView1.Rows.Count +height +120);
                    e.Graphics.DrawString("Total:  " + textBox1.Text + " RON", print10B, Brushes.Black, 40, dataGridView1.Rows.Count + 140 +height);
          
            }

  9. #9
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Print through WinForms

    ok but how many rows in that data gridview? How many rows does:

    dataGridView1.Rows.Count

    show?

    what about the setting up of the printer and its properties in your code?

    did you look at this also:

    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    8

    Re: Print through WinForms

    The number of rows is variable ... It is not a fix number , it might be 1 or 100.

  11. #11
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Print through WinForms

    right ok, thats fine but im asking in your example... how many rows are there? have you tried with more than 7? more than 10? does it still stop at the same point?
    also did you read the documentation? I believe you are missing setting the HasMorePages property to true if there are more pages to print. you need to redefine your logic slightly to indicate if there are more pages to print after you have printed your current page

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  12. #12

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    8

    Re: Print through WinForms

    If the number is below 7 everything is ok. If the number is above 7 the printer does not print the rest of document. As you can see i haven't tried to set HasMorePages() property. I read the printer documentation and it is kinda hard to implement that method so i thought maybe i might find something easier.

  13. #13
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Print through WinForms

    easy doesnt always cut it. you have got to follow the documentation for the product otherwise it wont work.... dont take the cheap road (which also wont work!)

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width