CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2005
    Location
    Singapore
    Posts
    40

    printer printing blank papers

    i tried for days to get this to work but it seems that no matter what code i write/use/change it never prints anything. I tried using a code to print from a richtextbox, from a textbox and this printing from a text file. i check the richtextbox method by using the image printer i could see the text and everything but when i print there is no text no line, Serious confused hope someone can help

    Code:
    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    
    namespace Kiosk2
    {
        public partial class DB : Form
        {
            public DB()
            {
                InitializeComponent();
            }
            private string idNum;
            public string sName
            {
                set
                {
                    idNum = value;
                }
            }
            Form1 frm1 = new Form1();
    
            private void DB_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'customersDataSet1.CustomerDB' table. You can move, or remove it, as needed.
                this.customerDBTableAdapter.Fill(this.customersDataSet1.CustomerDB);
    
    
    
                iDCardTextBox.Text = idNum.ToString();
                if (this.iDCardTextBox.Text != string.Empty)
                {
                    int indexs = iDCardListBox.FindStringExact(this.iDCardTextBox.Text);
                    if (indexs != ListBox.NoMatches)
                    {
                        //   DataGridViewSelectionMode.RowHeaderSelect;
                        // firstNameTextBox.Text = frm1.customerDBDataGridView.SelectedRows.ToString();
                        this.customerDBTableAdapter.FillByIDCard(this.customersDataSet1.CustomerDB, iDCardTextBox.Text);
                    }
                }
            }
    
            private void Show1_Click(object sender, EventArgs e)
            {
                textBox1.Text = "Hello World";
                rtxtBox1.Text = "Hello World";
                Show1.Hide();
                Show2.Hide();
                Show3.Hide();
                Show4.Hide();
                button1.Show();
                textBox1.Show();
    
            }
    
    System.IO.StreamReader fileToPrint;
    System.Drawing.Font printFont;
            protected void button1_Click(object sender, System.EventArgs e)
            {
                string printPath = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); //System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
               fileToPrint = new System.IO.StreamReader(printPath + @"\Kiosk2\printme.txt");
               printFont = new System.Drawing.Font("Arial", 10);
               printDocument1.Print();
               fileToPrint.Close();
            }
    
            private void printDocument1_printPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                float yPos = 0f;
                int count = 0;
                float leftMargin = e.MarginBounds.Left;
                float topMargin = e.MarginBounds.Top;
                string line = null;
                float linesPerPage = e.MarginBounds.Height/printFont.GetHeight(e.Graphics);
                while (count < linesPerPage)
                {
                    line = fileToPrint.ReadLine();
                    if (line == null)
                {
                    break;
                }
                    yPos = topMargin + count * printFont.GetHeight(e.Graphics);
                    e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
                    count++;
                }
                if (line != null)
                {
                e.HasMorePages = true;
                }
    }    
    
        }
    }
    Last edited by gret; January 17th, 2006 at 03:43 AM.

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

Featured