views:

15

answers:

0

In the following Form-code I have a FrmPrintKasTicket witch i start form another form. This Form should print a document based on information in a SQL database. When I use a button on this form (and remove the "PrintKasTicket();" under FrmKasTicket_Reload) it actually prints. But when I envoke the printKasTicket-methode when the Frm is loaded, it sort of happens 'to fast' for the file to load and it skippes that part, so we're stuck somewhere halfway printing (pd_PrintPage methode) because he complaines that the textboxes are empty (witch shouldn't have happend because i've filled the grid and the textboxes when i initialized my Form). The most strange thing is: my dad has Windows XP and Visual Studio 2005 (an earlier version) and he doesn't have my problems with the same application. My computer has Windows Vista en Visual studio 2005 SP3 and I do have those problems. Someone who has the answer to this mystery?

i'll be most grateful.

Inne

        namespace WindowsApplication3
        {
            public partial class FrmPrintKasTicket : Form
            {
                private int Ticketnr;
                private bool blFactuur;
                private Font printFont = new Font("Arial", 10);

        public FrmPrintKasTicket(int KasTicketnr, bool Factuur)
                {
                    InitializeComponent();
                    Ticketnr = KasTicketnr ;
                    blFactuur = Factuur;

                    verkoopHeaderKlantBindingSource.Filter = @"Kasticketnr=" + KasTicketnr;
                    verkoopDetailBindingSource.Filter = @"Kasticketnr=" + KasTicketnr;
                    FrmPrintKasTicket_ReLoad();
                }


                private void PrintKasTicket()
                {
                    PrintDocument pd = new PrintDocument();
                    pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
                    pd.PrinterSettings.Copies = 2;
                    pd.Print();
                    this.Close(); 

                }

private void btnPrint_Click(object sender, EventArgs e)
        {
            PrintKasTicket();

        }



                private void FrmPrintKasTicket_ReLoad()
                {
                    // TODO: This line of code loads data into the 'winkelDataSet.VerkoopHeaderKlant' table. You can move, or remove it, as needed.
                    this.verkoopHeaderKlantTableAdapter.Fill(this.winkelDataSet.VerkoopHeaderKlant);
                    // TODO: This line of code loads data into the 'winkelDataSet.VerkoopDetail' table. You can move, or remove it, as needed.
                    this.verkoopDetailTableAdapter.Fill(this.winkelDataSet.VerkoopDetail);
                    // TODO: This line of code loads data into the 'winkelDataSet.VerkoopHeaderKlant' table. You can move, or remove it, as needed.

                    PrintKasTicket();

                }



                private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
                {
                   // code for printing
    int regelTel = 0;
                Font PrFont = kasticketnrTextBox.Font;
                float PrLeft = e.MarginBounds.Left;
                float PrTop = e.MarginBounds.Top;
                float PrRight = e.MarginBounds.Right;
                float PrWidth = e.MarginBounds.Width;
                float Kolom1 = PrLeft + PrWidth * 0.16f;
                Brush borstel = Brushes.Black;

                e.Graphics.DrawString("Verbrugghe Modelbouw", PrFont, borstel, PrLeft, PrTop + PrFont.Height * 1);
                e.Graphics.DrawString("Koning Albert I laan 58", PrFont, borstel, PrLeft, PrTop + PrFont.Height * 2);
                e.Graphics.DrawString("8200 Sint-Michiels", PrFont, borstel, PrLeft, PrTop + PrFont.Height * 3);
                e.Graphics.DrawString("Tel : 050 ", PrFont, borstel, PrLeft, PrTop + PrFont.Height * 4);
                e.Graphics.DrawString("www.Verbrugghe Modelbouw.be", PrFont, borstel, PrLeft + PrWidth * 0.0f, PrTop + PrFont.Height * 5);
                e.Graphics.DrawString(Convert.ToString(tijdstipDateTimePicker.Value), PrFont, borstel, PrLeft + PrWidth * 0.6f, PrTop + PrFont.Height * 1);
                if (blFactuur)
                {
                    e.Graphics.DrawString("Klant " + Convert.ToString(klantnrTextBox.Text), PrFont, borstel, PrLeft + PrWidth * 0.6f, PrTop + PrFont.Height * 2);
                    e.Graphics.DrawString(Convert.ToString(klantnaamTextBox.Text), PrFont, borstel, PrLeft + PrWidth * 0.6f, PrTop + PrFont.Height * 3);
                    e.Graphics.DrawString(Convert.ToString(adresTextBox.Text), PrFont, borstel, PrLeft + PrWidth * 0.6f, PrTop + PrFont.Height * 4);
                    e.Graphics.DrawString(Convert.ToString(zipTextBox.Text) + " " + Convert.ToString(gemeenteTextBox.Text), PrFont, borstel, PrLeft + PrWidth * 0.6f, PrTop + PrFont.Height * 5);
                    e.Graphics.DrawString(Convert.ToString(bTWnrTextBox.Text), PrFont, borstel, PrLeft + PrWidth * 0.6f, PrTop + PrFont.Height * 6);
                }
                regelTel = 8;
                e.Graphics.DrawString("Barcode", PrFont, borstel, PrLeft + PrWidth * 0.0f, PrTop + PrFont.Height * regelTel);
                e.Graphics.DrawString("Promo", PrFont, borstel, PrLeft + PrWidth * 0.18f, PrTop + PrFont.Height * regelTel);
                e.Graphics.DrawString("Omschrijving", PrFont, borstel, PrLeft + PrWidth * 0.25f, PrTop + PrFont.Height * regelTel);
                e.Graphics.DrawString("Eenheidsprijs", PrFont, borstel, PrLeft + PrWidth * 0.65f, PrTop + PrFont.Height * regelTel);
                e.Graphics.DrawString("Aantal", PrFont, borstel, PrLeft + PrWidth * 0.8f, PrTop + PrFont.Height * regelTel);
                e.Graphics.DrawString("Totaal incl", PrFont, borstel, PrLeft + PrWidth * 0.9f, PrTop + PrFont.Height * regelTel);
                regelTel++;
                foreach (DataGridViewRow Row1 in verkoopDetailDataGridView.Rows)
                {
                    if (Convert.ToInt32(Row1.Cells[0].Value) == Ticketnr)
                    {
                        e.Graphics.DrawString(Convert.ToString(Row1.Cells[2].Value), PrFont, borstel, PrLeft + PrWidth * 0.0f, PrTop + PrFont.Height * regelTel);
                        e.Graphics.DrawString(Convert.ToString(Row1.Cells[5].Value), PrFont, borstel, PrLeft + PrWidth * 0.18f, PrTop + PrFont.Height * regelTel);
                        e.Graphics.DrawString(Convert.ToString(Row1.Cells[3].Value).Substring(0, 20), PrFont, borstel, PrLeft + PrWidth * 0.25f, PrTop + PrFont.Height * regelTel);
                        e.Graphics.DrawString(Convert.ToString(Row1.Cells[6].Value), PrFont, borstel, PrLeft + PrWidth * 0.65f, PrTop + PrFont.Height * regelTel);
                        e.Graphics.DrawString(Convert.ToString(Row1.Cells[4].Value), PrFont, borstel, PrLeft + PrWidth * 0.8f, PrTop + PrFont.Height * regelTel);
                        e.Graphics.DrawString(Convert.ToString(Math.Round(Convert.ToDouble(Row1.Cells[8].Value), 2)), PrFont, borstel, PrLeft + PrWidth * 0.9f, PrTop + PrFont.Height * regelTel);
                        regelTel++;
                    }
                }
                regelTel++;

                e.Graphics.DrawString("Btw bedrag ", PrFont, borstel, PrLeft, PrTop + PrFont.Height * regelTel);
                e.Graphics.DrawString(": " + Convert.ToString(Math.Round((Convert.ToDouble(prijsInclTextBox.Text) - Convert.ToDouble(prijsExclTextBox.Text)), 2)), PrFont, borstel, Kolom1, PrTop + PrFont.Height * regelTel);
                e.Graphics.DrawString(Convert.ToString(prijsInclTextBox.Text), PrFont, borstel, PrLeft + PrWidth * 0.9f, PrTop + PrFont.Height * regelTel);
                regelTel++;
                if (Convert.ToString(kortingTextBox.Text) != "0")
                {
                    e.Graphics.DrawString("Korting", PrFont, borstel, PrLeft, PrTop + PrFont.Height * regelTel);
                    e.Graphics.DrawString(": " + Convert.ToString(kortingTextBox.Text), PrFont, borstel, Kolom1, PrTop + PrFont.Height * regelTel);
                    regelTel++;
                }
                if (betaaldBonnenTextBox.Text != "0")
                {
                    e.Graphics.DrawString("Betaald Bonnen", PrFont, borstel, PrLeft, PrTop + PrFont.Height * regelTel);
                    e.Graphics.DrawString(": " + betaaldBonnenTextBox.Text, PrFont, borstel, Kolom1, PrTop + PrFont.Height * regelTel);
                    regelTel++;
                }
                if (betaaldCashTextBox.Text != "0")
                {
                    e.Graphics.DrawString("Betaald Cash ", PrFont, borstel, PrLeft, PrTop + PrFont.Height * regelTel);
                    e.Graphics.DrawString(": " + betaaldCashTextBox.Text, PrFont, borstel, Kolom1, PrTop + PrFont.Height * regelTel);
                    regelTel++;
                }
                if (betaaldElecTextBox.Text != "0")
                {
                    e.Graphics.DrawString("Betaalkaart", PrFont, borstel, PrLeft, PrTop + PrFont.Height * regelTel);
                    e.Graphics.DrawString(": " + betaaldElecTextBox.Text, PrFont, borstel, Kolom1, PrTop + PrFont.Height * regelTel);
                    regelTel++;
                }
                e.HasMorePages = false;
    }