且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#windows应用程序中从Windows窗体打印bankcheque上的值

更新时间:2023-10-19 22:03:22

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.