如何清除SaveFileDialog的内容?

编程入门 行业动态 更新时间:2024-10-24 00:21:48
本文介绍了如何清除SaveFileDialog的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨。 我正在开发一个Windows窗体应用程序,其中一个部分需要制作并将pdf文件保存到我PC上的所需位置。我想在同一个应用程序中制作2个不同的文件(不关闭应用程序并再次运行) 例如,我把文本框中的文本,该文件应该包含该文本,并在单击按钮SaveFileDialog应该打开后,我将此文件保存到我的PC(这部分正在做精细)。然后我从文本框中删除文本,然后在其中添加新文本。如果我再次按下按钮并选择正确的位置,它将保存与以前相同的文件(具有与之前相同的内容)。我怎么处理这个问题呢? 编辑: SaveFileDialog pdfFile = new SaveFileDialog(); pdfFile.Filter = PDF | * .pdf; pdfFile.Title = aaPDF; pdfFile.FileName = aaa; BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA,BaseFont.CP1250, false ); pdfFont titleFont = new pdfFont(bf, 20 ); pdfFont infoFont = new pdfFont(bf, 12 ); pdfFont questionsFont = new pdfFont(bf, 14 ); Chunk glue = new 块( new VerticalPositionMark()); if (pdfFile.ShowDialog()== System.Windows.Forms.DialogResult.OK) {文档文档= 新文档(iTextSharp.text.PageSize.A4, 40 , 40 , 50 , 50 ); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFile.FileName,FileMode.Create)); document.Open(); document.NewPage(); ParagraphPDF title = new ParagraphPDF( AAA ,titleFont); title.Alignment = Element.ALIGN_CENTER; document.Add(title); document.Add(Chunk.NEWLINE); ParagraphPDF p1 = new ParagraphPDF(textFromTextbox,infoFont); document.Add(p1); document.Close(); }

解决方案

在代码中放置断点:当您点击断点时单步执行代码并检查变量的值。在Visual Studio中使用F11单步执行。 您要么覆盖文件,要么没有访问TextBox中更改的内容。这应该很容易理解。

if (pdfFile.ShowDialog()== System.Windows.Forms.DialogResult.OK) { // 在这里设置一个断点:单步前进 凭证凭证= 新凭证(iTextSharp.text.PageSize.A4, 40 , 40 , 50 , 50 ); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFile.FileName,FileMode.Create)); document.Open(); document.NewPage(); ParagraphPDF title = new ParagraphPDF( AAA ,titleFont); title.Alignment = Element.ALIGN_CENTER; document.Add(title); document.Add(Chunk.NEWLINE); ParagraphPDF p1 = new ParagraphPDF(textFromTextbox,infoFont); // 在这里设置一个断点:单步前进 document.Add(p1); // 在这里设置一个断点:单步前进 document.Close(); }

此外,在此代码返回后放置一个断点。

您可以修改 SaveFileDialog的属性。 FileName 。
-SA

Hi. I'm working on a windows forms app which, in one of its parts needs to make and save pdf file to desired location on my PC. I want to make 2 different files in the same app (NOT closing the app and running it again) For example, I put the text in the textbox, the file should contain that text and after clicking the button SaveFileDialog should open and I will save this file to my PC (THIS PART IS DOING FINE). Then I erase the text from textbox and I add new text in it. If I press the button again and choose the proper location, It will save the same file as before (with the same content as before). How can I deal with this problem? EDIT:

SaveFileDialog pdfFile = new SaveFileDialog(); pdfFile.Filter = "PDF|*.pdf"; pdfFile.Title = "aaPDF"; pdfFile.FileName = "aaa"; BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false); pdfFont titleFont = new pdfFont(bf, 20); pdfFont infoFont = new pdfFont(bf, 12); pdfFont questionsFont = new pdfFont(bf, 14); Chunk glue = new Chunk(new VerticalPositionMark()); if (pdfFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Document document = new Document(iTextSharp.text.PageSize.A4, 40, 40, 50, 50); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFile.FileName, FileMode.Create)); document.Open(); document.NewPage(); ParagraphPDF title = new ParagraphPDF("AAA", titleFont); title.Alignment = Element.ALIGN_CENTER; document.Add(title); document.Add(Chunk.NEWLINE); ParagraphPDF p1 = new ParagraphPDF(textFromTextbox, infoFont); document.Add(p1); document.Close(); }

解决方案

Put break-points in your code: when you hit the break-points single-step through your code and examine the values of the variables. Use F11 to single-step in Visual Studio. Either you are over-writing the file, or you are not accessing the changed content in the TextBox. This should be simple to figure out.

if (pdfFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // put a break-point here: single-step forward Document document = new Document(iTextSharp.text.PageSize.A4, 40, 40, 50, 50); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFile.FileName, FileMode.Create)); document.Open(); document.NewPage(); ParagraphPDF title = new ParagraphPDF("AAA", titleFont); title.Alignment = Element.ALIGN_CENTER; document.Add(title); document.Add(Chunk.NEWLINE); ParagraphPDF p1 = new ParagraphPDF(textFromTextbox, infoFont); // put a break-point here: single-step forward document.Add(p1); // put a break-point here: single-step forward document.Close(); }

Also, put a break-point just after this code returns.

You can modify the property of SaveFileDialog.FileName.
—SA

更多推荐

如何清除SaveFileDialog的内容?

本文发布于:2023-11-03 16:25:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   SaveFileDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!