Click here to Skip to main content
15,902,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a form in that bankname and accountno and account type comboboxes and account payee check box,receivername textbox,amount textbox,rupeesinwords textbox and checkbbook no and checkno and one save button.What i want is after filling all the details and save data into database then i want print that cheque without using another form. the data into database and then i click the print button document will go to print.After long googling I tried some code.It is giving "Documents doesnot conatain any pages" message how to do it please help me on this.I'm fresher.Thanks in advance.

What I have tried:

C#
<blockquote class="quote"><div class="op">Quote:</div> 
 
    private void btnsave_Click(object sender, EventArgs e)
        {
            ChqMngrBsns.Masters.WriteChkInfo writeinfo = new 
   ChqMngrBsns.Masters.WriteChkInfo();
            if (cmbBankname.SelectedIndex == 0)
            {
                MessageBox.Show("Select Bank");
                return;
            }
            else if (cmbpayee.SelectedIndex == 0)
            {
              MessageBox.Show("Enter ReceiverName");
                return;
            }
            else if (txtAmnt.Text =="" || txtAmnt.Text==string.Empty)
            {
                MessageBox.Show("Enter Amount");
                 return;
            }
            if (bankid > 0)
            {
                writeinfo.bankid = bankid;
                if (chkAcntpyee.Checked == true)
                {
                   writeinfo.IsActpayee = true;
                }
                else
                {
                   writeinfo.IsActpayee = false;
                }
                writeinfo.pay = cmbpayee.Text.ToString();
                writeinfo.Amount = Convert.ToDecimal(txtAmnt.Text);
                writeinfo.Chkbookno = Convert.ToInt32(cmbckbno.GetItemText(cmbckbno.SelectedItem));
                writeinfo.Chkno = Convert.ToInt32(cmbChqno.GetItemText(cmbChqno.SelectedItem));
                writeinfo.Isprint = true;
                writeinfo.SaveData(true);
                 btnprint.Enabled = true;
            }
            ClearControls(this);
        }
        private void btnprint_Click(object sender, EventArgs e)
        {   
            CaptureScreen();
            printDocument1.Print();
            printPreviewDialog1.ShowDialog();
            ClearControls(this);
        }
        Bitmap memoryImage;
        private void CaptureScreen()
        {
            Graphics myGraphics = this.CreateGraphics();
            Size s = this.Size;
            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 1060,360, s);
        }
        private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 1060, 360);
        }
        
    }
}

</blockquote>
Posted
Updated 25-May-17 0:06am
v3

1 solution

Use the PrintDocument Class (System.Drawing.Printing)[^] - the link includes a basic example.
 
Share this answer
 
Comments
Member 13153537 25-May-17 1:08am    
My Requirement is after filling the form and then click save button data save into the database and then print button enable .After i click the print button it will go to print.I was stuck since yesterday.Please help me how to start.I'm fresher.Thanks in Advance.
OriginalGriff 25-May-17 3:07am    
Follow the link, read the text.
Then look at the example code ...
Member 13153537 25-May-17 6:08am    
Now i tried something but i'm getting documents doesnot contain any pages.how to solve that.Please have look at my question once.Thanks.
OriginalGriff 25-May-17 6:18am    
Instead of just guessing and hoping for the best, why not just copy the code from the example, and give that a try first?
When you have that working, then start to replace the stuff it prints with what you actually want...
Member 13153537 29-May-17 2:43am    
What link did you shared to me in that path is there.How to we set the file in that location.Please guide me how to do this.

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