本文介绍了如何在窗口申请C#中准备学费收据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在记事本(.txt)中准备了下面给出的收据设计 I have prepared receipt design given below in Notepad(.txt) School Name School Address-----------------------------------------------Receipt No: 66666 Date: 28/1/2017Name:Sandeep kumar singh Class X-A F. Name :Mahendra singh Month :February ------------------------------------------------Particular Payable Paid------------------------------------------------Tution Fee 500 500Transport 700 700Exam Fee 100 100------------------------------------------------Total 1300 1300------------------------------------------------Dues:0 Signature------------------------------------------------- 但我想更新收据详细信息,如学生详细信息,学校名称,地址等。在记事本的时候学生存入他们的费用,然后必须打印他们的详细信息。 我尝试了什么: But I want to Update Receipt detail like Student detail,School Name,address Etc.in notepad when student deposit their fee,then their detail must be printed.What I have tried:private void btn_print_Click(object sender, EventArgs e) { try { streamToPrint = new StreamReader("D:\\ZDXC.txt"); try { printFont = new Font("Verdana", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler (this.printDocument1_PrintPage); pd.Print(); } finally { streamToPrint.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void printDocument1_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; string line = null; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); // Print each line of the file. while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null)) { yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } // If more lines exist, print another page. if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; } 推荐答案 {SchoolName} {SchoolAddress}-----------------------------------------------Receipt No: {RecNo} Date: {Date}Name: {StudName} Class {StudClass}F. Name : {FName} Month : {Month}------------------------------------------------Particular Payable Paid------------------------------------------------Tution Fee {TFDue} {TFPaid}Transport {TRDue} {TrPaid}Exam Fee {EFDue} {EFPaid}------------------------------------------------Total {TotDue} {TotPaid}------------------------------------------------Dues: {Dues} Signature------------------------------------------------- 那么你可以只需使用string.Replace来填空: Then you can just use string.Replace to "fill in the blanks":string receipt = template.Replace("{SchoolName}", "Myschool");receipt = receipt.Replace("{SchoolAddress}", "TheBigBuildingFullOfStudents, This Road, That town");receipt = receipt.Replace("{RecNo}", (receiptNo++).ToString());receipt = receipt.Replace("{Date}", DateTime.Now.ToShortDateString());...试一试 - 你会明白我的意思!Give it a try - you'll see what I mean! 这篇关于如何在窗口申请C#中准备学费收据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 09:26