Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a winform in that datetime picker,pay name ,amount and rupeesinwords fields.
what i want is i put blank bankcheque in the printer and fill the form and click the print button i entered data is fill in the respective places on the bank cheque
like date boxes date and payname place pay name like that.How to do this.I tried some code payname and rupees need to move below remaining working fine.If anybody already done this please help me.Thanks in Advance.

What I have tried:

C#
private void btnprint_Click(object sender, EventArgs e)
     {
       PrintDocument p = new PrintDocument();
       p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
      {
        e1.Graphics.DrawString(PrintDate, new Font("verdana", 10), new
    SolidBrush(Color.Black), new RectangleF(620, 3,
    p.DefaultPageSettings.PrintableArea.Width,
    p.DefaultPageSettings.PrintableArea.Height));
    e1.Graphics.DrawString(AccountPayee, new Font("verdana", 10), new
    SolidBrush(Color.Black), new RectangleF(20, 30,
    p.DefaultPageSettings.PrintableArea.Width,
    p.DefaultPageSettings.PrintableArea.Height));
    e1.Graphics.DrawString(PrintpayName, new Font("verdana", 10), new
    SolidBrush(Color.Black), new RectangleF(55, 60,
    p.DefaultPageSettings.PrintableArea.Width,
    p.DefaultPageSettings.PrintableArea.Height));
    e1.Graphics.DrawString(PrintRups, new Font("verdana", 10), new
    SolidBrush(Color.Black), new RectangleF(90, 90,
    p.DefaultPageSettings.PrintableArea.Width,
    p.DefaultPageSettings.PrintableArea.Height));
    e1.Graphics.DrawString(PrintAmount, new Font("verdana", 10), new
    SolidBrush(Color.Black), new RectangleF(695, 120,
    p.DefaultPageSettings.PrintableArea.Width,
    p.DefaultPageSettings.PrintableArea.Height));
     };
Posted
Updated 2-Jun-17 19:19pm
v3
Comments
OriginalGriff 2-Jun-17 1:54am    
And?
What is it doing that you didn't expect, or not doing that you did?
What help do you need?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Member 13153537 2-Jun-17 2:01am    
My question is i put the bankcheque on printer and create somestrings for the date and payname and amount and rupessinwords text.If i click the print the button that strings will be place on the bank cheque date field opposite date and amount opposite amount like that.how to get the dimensions of the that places how to do that please help me i tried above code.

1 solution

Quote:
My question is i put the bankcheque on printer and create somestrings for the date and payname and amount and rupessinwords text.If i click the print the button that strings will be place on the bank cheque date field opposite date and amount opposite amount like that.how to get the dimensions of the that places how to do that please help me i tried above code.


You measure the cheque, and find out exactly where the strings are supposed to go. For simplicity, use inches: the default measurement system for PrintDocument Graphics contexts in 1/100th of an inch per Point. So a location (55, 60) will be 0.55 inches from the left, and 0.60 inches from the top.

I'd start by creating appropriately sized Rectangle objects (one per area on the cheque) and drawing them as solid rectangles in different colours. When you have them all printing in the right place every time, you can use those rectangles to print you text.

But do yourself a favour: Abstract the check printing code into a separate class, and call a method passing the appropriate graphics context and the items to print instead of inline delegating the code: it makes life a whole load easier when there are changes needed later.
And don't create new font items like that - they are scarce resources, and need to be correctly Disposed or your application will rapidly run out of memory. Creating them every time you print is a recipe for an application that crashes unpredictably.
 
Share this answer
 
Comments
Member 13153537 2-Jun-17 2:54am    
Thank you very much for your support.
OriginalGriff 2-Jun-17 3:20am    
You're welcome!
Member 13153537 2-Jun-17 3:26am    
Once you done the preparing rectangle objects please share me.Thanks in Advance.
OriginalGriff 2-Jun-17 3:44am    
I can't do that for you - I don't have any access to your cheques!
Get out a ruler, start measuring, and create the appropriate Rectangle objects.
Dave Kreskowiak 3-Jun-17 10:15am    
So how much of your coffee did you spew all over your monitor? :)

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