如何在C#windows应用程序中从Windows窗体打印bankcheque上的值 [英] How to print the values on the bankcheque from the windows forms in C# windows application

查看:100
本文介绍了如何在C#windows应用程序中从Windows窗体打印bankcheque上的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在日期时间选择器,付款名称,金额和卢比字段中有一个winform。

我想要的是我在打印机中放入空白bankcheque并填写表单并单击我输入的打印按钮数据填写在银行检查的相应位置

像日期框日期和payname地方支付名称那样。如何做到这一点。我尝试了一些代码payname和卢比需要移动到下面保持工作正常。如果有人已经这样做了,请帮助我。谢谢。



我尝试过的事情:



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:

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));
     };

推荐答案

Quote:

我的问题是我把bankcheque放在打印机上,并为日期和工资名称和金额以及rupessinwords文本创建一些字符串。如果我点击打印按钮,字符串将放在银行检查日期字段对面的日期和金额相反的数量。如何获得那些地方的尺寸如何做到这一点,请帮助我,我尝试上面的代码。

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.





你测量检查,并找出确切的字符串应该去哪里。为简单起见,使用英寸:PrintDocument Graphics上下文的默认测量系统,每点1/100英寸。所以一个位置(55,60)距离左边0.55英寸,距离顶部0.60英寸。



我首先创建适当大小的Rectangle对象(检查中每个区域一个)并将它们绘制成不同颜色的实心矩形。如果你每次都在正确的位置打印它们,你可以使用那些矩形打印文本。



但是请帮个忙:摘要支票打印代码进入一个单独的类,并调用一个方法传递适当的图形上下文和要打印的项目而不是内联委托代码:当以后需要更改时,它会使生活变得更加容易。

并且不要不要创建像这样的新字体项 - 它们是稀缺资源,需要正确处理,否则你的应用程序将很快耗尽内存。每次打印时创建它们都是一个无法预测崩溃的应用程序的配方。



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.


这篇关于如何在C#windows应用程序中从Windows窗体打印bankcheque上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆