将列表框的项目保存到文本文件
如何使用 SaveFileDialog
将 listbox
项目的内容保存到文本文件?
我还想向文本文件添加其他信息,并添加一个 MessageBox
说明成功时已保存。
How can I save the contents of my listbox
items to a text file using a SaveFileDialog
?
I also want to add additional information to the text file and also add a MessageBox
saying saved when it's been successful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
另请注意
StreamWriter
的类型为 编码。Also take note the
StreamWriter
has a Type of Encoding.这应该可以做到。
this should do it.
SaveFileDialog
与ShowDialog()
一起使用以将其显示给用户,如果成功,则使用其OpenFile()
获取 ( File)Stream
您写入的内容。 msdn 页面上有一个示例。ListBox
可以通过其Items
属性进行访问,该属性只是其上项目的集合。A
SaveFileDialog
is used withShowDialog()
to show it to the user, and if it's successful, using itsOpenFile()
to get the (File)Stream
that you write to. There's an example on the msdn page.A
ListBox
can be accessed through itsItems
property, which is simply a collection of the items on it.保存
消息
To Save
Message
那里发生了一些事情 - 确保将它们分开,例如
请注意!!保存文件时可能会出现无数的异常,查看文档并以某种方式处理它们......
You have a few things going on there - make sure you split them up, e.g.
Please note!! There is a myriad of exceptions you can get while saving a file, see the docs and handle them somehow...