Visual Basic,打印和保存列表视图 [英] Visual Basic, Printing and saving a listview

查看:78
本文介绍了Visual Basic,打印和保存列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于将ListBox保存到文件的当前代码....



  Public   Sub  logfile()
Dim FILE_NAME 作为 字符串 = F:\ NEWWFolder \FileLog.txt

Dim cnt 正如 整数

Dim objwriter As System.IO.StreamWriter(FILE_NAME, True

cnt< ListBox1.Items.Count

objwriter.WriteLine(ListBox1.Items(cnt),字体( Time New Roman 30 ),Brushes.Black, 200 200 +(cnt * 32 ))

cnt = cnt + 1
循环

objwriter.Close()

结束 Sub


感谢您的帮助:D

解决方案

首先,正如Wes Aday在对该问题的评论中所建议的那样,只需阅读 ListView 上的文档。您没有告诉我们该类型的确切全名,但它可能是以下三种中的一种:

http://msdn.microsoft.com/en-us/library/system.windows.forms.listview%28v=vs.110% 29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.controls.listview%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview%28v=vs.110%29.aspx [ ^ ]。



原则上,它可能是其他类似但不相关的类型。你现在能看到在你的问题中指出确切类型名称以及应用程序类型有多重要吗?



现在,没有硬编码文件路径的情况,例如你的F:\ NEWFFolder \FileLog.txt,可能会有用。您是否了解目标系统上可能无法使用(或可访问)驱动器F:甚至C:。此外,代码可以在某些操作系统上的Mono或其他CLR上运行,例如使用类似Unix的,其中没有驱动器号的概念。应始终在运行时根据用户输入,一些配置文件,环境等计算文件路径。



最后,您可以使用名为 PrintDocument 的类,一个或另一个:

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110 %29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.printing.printdocument%28v=vs.95%29.aspx [ ^ ]。



-SA


I have this current code for saving a ListBox to a file....

Public Sub logfile()
Dim FILE_NAME As String = "F:\NEwFolder\FileLog.txt"

Dim cnt As Integer

Dim objwriter As New System.IO.StreamWriter(FILE_NAME, True)

Do While cnt < ListBox1.Items.Count

objwriter.WriteLine(ListBox1.Items(cnt), New Font("Time New Roman", 30), Brushes.Black, 200, 200 + (cnt * 32))

cnt = cnt + 1
Loop

objwriter.Close()

End Sub

I have swapped the listbox for a listview, How can I adapt this code to work for the listview?

Thanks for any Help :D

解决方案

First of all, as Wes Aday advised in his comment to the question, just read the documentation on ListView. You did not tell us exact full name of the type, but it could be this one of these three:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.listview%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview%28v=vs.110%29.aspx[^].

In principle, it could be some other, similar but unrelated type. Can you see now how important to indicate exact type names in your questions, as well as application type?

Now, there are no cases when hard-coded file paths, such as your ""F:\NEwFolder\FileLog.txt"", could be useful. Do you understand that the drive "F:" and even "C:" might not be available (or accessible) on the target system. Moreover, the code could be run on Mono or other CLR on some OS, such use Unix-like, where there is not such thing as the concept of "drive letter". File paths should always be calculated during run-time, based on user input, some configuration files, environment, and so on.

Finally, you can do printing using the class named "PrintDocument", one or another:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx[^],
or http://msdn.microsoft.com/en-us/library/system.windows.printing.printdocument%28v=vs.95%29.aspx[^].

—SA


这篇关于Visual Basic,打印和保存列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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