用VB.NET写的一个简易的RSS阅读器

o_EasyRssReader.gif
源代码如下:
None.gifImports System.Xml 
None.gif
Imports System.Threading 
None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public Class Form1Class Form1 
InBlock.gif
Inherits System.Windows.Forms.Form 
InBlock.gif#Region 
" Windows 窗体设计器生成的代码 " 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Public Sub New()Sub New() 
InBlock.gif
MyBase.New() 
InBlock.gif
InBlock.gif
'该调用是 Windows 窗体设计器所必需的。 
InBlock.gif
InitializeComponent() 
InBlock.gif
InBlock.gif
'在 InitializeComponent() 调用之后添加任何初始化 
InBlock.gif

ExpandedSubBlockEnd.gif
End Sub
 
InBlock.gif
InBlock.gif
'窗体重写 dispose 以清理组件列表。 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean
InBlock.gif
If disposing Then 
InBlock.gif
If Not (components Is NothingThen 
InBlock.gifcomponents.Dispose() 
InBlock.gif
End If 
InBlock.gif
End If 
InBlock.gif
MyBase.Dispose(disposing) 
ExpandedSubBlockEnd.gif
End Sub
 
InBlock.gif
InBlock.gif
'Windows 窗体设计器所必需的 
InBlock.gif
Private components As System.ComponentModel.IContainer 
InBlock.gif
InBlock.gif
'注意: 以下过程是 Windows 窗体设计器所必需的 
InBlock.gif'
可以使用 Windows 窗体设计器修改此过程。 
InBlock.gif'
不要使用代码编辑器修改它。 
InBlock.gif
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox 
InBlock.gif
Friend WithEvents Button1 As System.Windows.Forms.Button 
InBlock.gif
Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser 
InBlock.gif
Friend WithEvents Label1 As System.Windows.Forms.Label 
InBlock.gif
Friend WithEvents Label2 As System.Windows.Forms.Label 
InBlock.gif
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox 
InBlock.gif
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar 
InBlock.gif
Friend WithEvents Label4 As System.Windows.Forms.Label 
ExpandedSubBlockStart.gifContractedSubBlock.gif
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent() 
InBlock.gif
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) 
InBlock.gifMe.ListBox1 
= New System.Windows.Forms.ListBox 
InBlock.gifMe.Button1 
= New System.Windows.Forms.Button 
InBlock.gifMe.AxWebBrowser1 
= New AxSHDocVw.AxWebBrowser 
InBlock.gifMe.Label1 
= New System.Windows.Forms.Label 
InBlock.gifMe.Label2 
= New System.Windows.Forms.Label 
InBlock.gifMe.TextBox1 
= New System.Windows.Forms.TextBox 
InBlock.gifMe.StatusBar1 
= New System.Windows.Forms.StatusBar 
InBlock.gifMe.Label4 
= New System.Windows.Forms.Label 
InBlock.gif
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).BeginInit() 
InBlock.gifMe.SuspendLayout() 
InBlock.gif
' 
InBlock.gif'
ListBox1 
InBlock.gif'
 
InBlock.gif
Me.ListBox1.Location = New System.Drawing.Point(067
InBlock.gifMe.ListBox1.Name 
= "ListBox1" 
InBlock.gifMe.ListBox1.Size 
= New System.Drawing.Size(727108
InBlock.gifMe.ListBox1.TabIndex 
= 0 
InBlock.gif
' 
InBlock.gif'
Button1 
InBlock.gif'
 
InBlock.gif
Me.Button1.Location = New System.Drawing.Point(6295
InBlock.gifMe.Button1.Name 
= "Button1" 
InBlock.gifMe.Button1.Size 
= New System.Drawing.Size(9456
InBlock.gifMe.Button1.TabIndex 
= 1 
InBlock.gifMe.Button1.Text 
= "读取" 
InBlock.gif
' 
InBlock.gif'
AxWebBrowser1 
InBlock.gif'
 
InBlock.gif
Me.AxWebBrowser1.Enabled = True 
InBlock.gifMe.AxWebBrowser1.Location 
= New System.Drawing.Point(-7184
InBlock.gifMe.AxWebBrowser1.OcxState 
= CType(resources.GetObject("AxWebBrowser1.OcxState"), System.Windows.Forms.AxHost.State) 
InBlock.gifMe.AxWebBrowser1.Size 
= New System.Drawing.Size(727480
InBlock.gifMe.AxWebBrowser1.TabIndex 
= 2 
InBlock.gif
' 
InBlock.gif'
Label1 
InBlock.gif'
 
InBlock.gif
Me.Label1.Location = New System.Drawing.Point(026
InBlock.gifMe.Label1.Name 
= "Label1" 
InBlock.gifMe.Label1.Size 
= New System.Drawing.Size(62415
InBlock.gifMe.Label1.TabIndex 
= 3 
InBlock.gifMe.Label1.Text 
= "网站地址:" 
InBlock.gif
' 
InBlock.gif'
Label2 
InBlock.gif'
 
InBlock.gif
Me.Label2.Location = New System.Drawing.Point(045
InBlock.gifMe.Label2.Name 
= "Label2" 
InBlock.gifMe.Label2.Size 
= New System.Drawing.Size(62414
InBlock.gifMe.Label2.TabIndex 
= 4 
InBlock.gifMe.Label2.Text 
= "网站描述:" 
InBlock.gif
' 
InBlock.gif'
TextBox1 
InBlock.gif'
 
InBlock.gif
Me.TextBox1.Location = New System.Drawing.Point(720
InBlock.gifMe.TextBox1.Name 
= "TextBox1" 
InBlock.gifMe.TextBox1.Size 
= New System.Drawing.Size(55220
InBlock.gifMe.TextBox1.TabIndex 
= 6 
InBlock.gifMe.TextBox1.Text 
= "Http://Blog.CSDN.Net/AppleBBS/Rss.aspx" 
InBlock.gif
' 
InBlock.gif'
StatusBar1 
InBlock.gif'
 
InBlock.gif
Me.StatusBar1.Location = New System.Drawing.Point(0495
InBlock.gifMe.StatusBar1.Name 
= "StatusBar1" 
InBlock.gifMe.StatusBar1.Size 
= New System.Drawing.Size(72622
InBlock.gifMe.StatusBar1.TabIndex 
= 7 
InBlock.gifMe.StatusBar1.Text 
= "StatusBar1" 
InBlock.gif
' 
InBlock.gif'
Label4 
InBlock.gif'
 
InBlock.gif
Me.Label4.Location = New System.Drawing.Point(06
InBlock.gifMe.Label4.Name 
= "Label4" 
InBlock.gifMe.Label4.Size 
= New System.Drawing.Size(7212
InBlock.gifMe.Label4.TabIndex 
= 8 
InBlock.gifMe.Label4.Text 
= "RSS地址:" 
InBlock.gifMe.Label4.TextAlign 
= System.Drawing.ContentAlignment.MiddleLeft 
InBlock.gif
' 
InBlock.gif'
Form1 
InBlock.gif'
 
InBlock.gif
Me.AutoScaleBaseSize = New System.Drawing.Size(513
InBlock.gifMe.ClientSize 
= New System.Drawing.Size(726517
InBlock.gifMe.Controls.Add(Me.Label4) 
InBlock.gifMe.Controls.Add(Me.StatusBar1) 
InBlock.gifMe.Controls.Add(Me.TextBox1) 
InBlock.gifMe.Controls.Add(Me.Label2) 
InBlock.gifMe.Controls.Add(Me.Label1) 
InBlock.gifMe.Controls.Add(Me.AxWebBrowser1) 
InBlock.gifMe.Controls.Add(Me.Button1) 
InBlock.gifMe.Controls.Add(Me.ListBox1) 
InBlock.gifMe.Name 
= "Form1" 
InBlock.gifMe.StartPosition 
= System.Windows.Forms.FormStartPosition.CenterScreen 
InBlock.gifMe.Text 
= "Easy RSS Reader" 
InBlock.gif
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).EndInit() 
InBlock.gifMe.ResumeLayout(
False
InBlock.gif
ExpandedSubBlockEnd.gif
End Sub
 
InBlock.gif
InBlock.gif#
End Region 
InBlock.gif
Private thread As Thread '定义一个线程 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub loadrss()Sub loadrss() '读取RSS文件并取出内容标题的过程 
InBlock.gif
StatusBar1.Text = "正在读取" & TextBox1.Text & "并效验" 
InBlock.gifMe.loadxmltocache(TextBox1.Text) 
InBlock.gifStatusBar1.Text 
= "正在读取相关网站信息" 
InBlock.gifMe.loadtitle() 
InBlock.gifStatusBar1.Text 
= "正在读取相RSS内容项" 
InBlock.gifMe.loaditem() 
InBlock.gifStatusBar1.Text 
= "完成" 
ExpandedSubBlockEnd.gif
End Sub
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
InBlock.gif
Try 
InBlock.gifthread 
= New Thread(AddressOf loadrss) 
InBlock.gifthread.Start() 
InBlock.gif
Catch ex As Exception 
InBlock.gif
MsgBox(ex.ToString) 
InBlock.gif
End Try 
ExpandedSubBlockEnd.gif
End Sub
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
InBlock.gifAxWebBrowser1.Width 
= Me.Width 
InBlock.gifStatusBar1.Text 
= "就绪" 
ExpandedSubBlockEnd.gif
End Sub
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub loadxmltocache()Sub loadxmltocache(ByVal URL As String
InBlock.gif
'读取RSS文件并存放在本地以供操作 
InBlock.gif
Dim xmldocument As New XmlDocument 
InBlock.gifxmldocument.Load(URL) 
InBlock.gifxmldocument.Save(Application.StartupPath 
& "~doc.xml"
ExpandedSubBlockEnd.gif
End Sub
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub loadtitle()Sub loadtitle() 
InBlock.gif
'从本地文件中进行操作,读取RSS中有关网站的信息 
InBlock.gif
Dim xmlDocument As New XmlDocument 
InBlock.gifxmlDocument.Load(Application.StartupPath 
& "~doc.xml"
InBlock.gif
Dim mynodelist As XmlNodeList 
InBlock.gifmynodelist 
= xmlDocument.SelectNodes("/rss/channel"
InBlock.gifLabel1.Text 
= "网站:" & Trim(mynodelist(0).Item("title").InnerText()) 
InBlock.gifLabel2.Text 
= "描述:" & Trim(mynodelist(0).Item("description").InnerText()) 
ExpandedSubBlockEnd.gif
End Sub
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub loaditem()Sub loaditem() 
InBlock.gif
'从本地文件中进行操作,读取RSS中内容的标题及作者 
InBlock.gif
Dim xmlDocument As New XmlDocument 
InBlock.gifxmlDocument.Load(Application.StartupPath 
& "~doc.xml"
InBlock.gif
Dim mynodelist As XmlNodeList 
InBlock.gifmynodelist 
= xmlDocument.SelectNodes("/rss/channel/item"
InBlock.gifListBox1.Items.Clear() 
InBlock.gif
Dim i As Integer 
InBlock.gif
For i = 0 To mynodelist.Count - 1 
InBlock.gifListBox1.Items.Add(
"[" & Trim(mynodelist(i).Item("dc:creator").InnerText()) & "]" & Trim(mynodelist(i).Item("title").InnerText())) 
InBlock.gif
Next 
ExpandedSubBlockEnd.gif
End Sub
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub ListBox1_SelectedIndexChanged()Sub ListBox1_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged 
InBlock.gifthread 
= New Thread(AddressOf loadhtml) 
InBlock.gifthread.Start() 
ExpandedSubBlockEnd.gif
End Sub
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub loadhtml()Sub loadhtml() 
InBlock.gif
'读取RSS中对应文件的内容并存到临时文件后显示 
InBlock.gif
Dim xmlDocument As New XmlDocument 
InBlock.gifxmlDocument.Load(Application.StartupPath 
& "~doc.xml"
InBlock.gif
Dim mynodelist As XmlNodeList 
InBlock.gifmynodelist 
= xmlDocument.SelectNodes("/rss/channel/item"
InBlock.gif
Dim i As Integer 
InBlock.gif
Dim j As Boolean 
InBlock.gif
Dim content As String 
InBlock.gifStatusBar1.Text 
= "正在读取文章内容" 
InBlock.gif
For i = 0 To mynodelist.Count - 1 
InBlock.gif
If ListBox1.SelectedItem = "[" & Trim(mynodelist(i).Item("dc:creator").InnerText()) & "]" & Trim(mynodelist(i).Item("title").InnerText()) Then 
InBlock.gifcontent 
= content & "<html><head><meta http-equiv='content-type' content='text/html;charset=UTF-8'></head><body leftmargin='5' topmargin='0' rightmargin='0'>" 
InBlock.gifcontent 
= content & "<table width='100%' height='80' bgcolor='#eeeeee'><tr><td><b>标题:</b><a href='" 
InBlock.gifcontent 
= content & Trim(mynodelist(i).Item("link").InnerText()) 
InBlock.gifcontent 
= content & "'>" 
InBlock.gifcontent 
= content & Trim(mynodelist(i).Item("title").InnerText()) 
InBlock.gifcontent 
= content & "</a><br><b>作者:</b>" 
InBlock.gifcontent 
= content & Trim(mynodelist(i).Item("dc:creator").InnerText()) 
InBlock.gifcontent 
= content & "<br><b>日期:</b>" 
InBlock.gifcontent 
= content & Trim(mynodelist(i).Item("pubDate").InnerText()) 
InBlock.gifcontent 
= content & "</td></tr></table><table><tr><td><b>摘要:</b>" 
InBlock.gifcontent 
= content & formatHtml(mynodelist(i).Item("description").InnerText()) 
InBlock.gifcontent 
= content & "</td></tr></table></body></html>" 
InBlock.gif
= SaveTextFile(Application.StartupPath & "~temp.html", content) 
InBlock.gifAxWebBrowser1.Navigate(Application.StartupPath 
& "~temp.html"
InBlock.gif
Exit For 
InBlock.gif
End If 
InBlock.gif
Next 
InBlock.gifStatusBar1.Text 
= "完成" 
ExpandedSubBlockEnd.gif
End Sub
 
InBlock.gif
'写文件的过程 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Function SaveTextFile()Function SaveTextFile(ByVal FilePath As StringByVal FileContent As StringAs Boolean 
InBlock.gif
Dim sw As System.IO.StreamWriter 
InBlock.gif
Try 
InBlock.gifsw 
= New System.IO.StreamWriter(FilePath, False
InBlock.gifsw.
Write(FileContent) 
InBlock.gif
Return True 
InBlock.gif
Catch e As Exception 
InBlock.gif
Return False 
InBlock.gif
Finally 
InBlock.gif
If Not sw Is Nothing Then sw.Close() 
InBlock.gif
End Try 
ExpandedSubBlockEnd.gif
End Function
 
InBlock.gif
'从地址里取网址的函数 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Function formatURL()Function formatURL(ByVal str As StringAs String 
InBlock.gif
Dim sStr As String 
InBlock.gif
Dim i As Integer 
InBlock.gif
Dim j As Integer 
InBlock.gif
For i = 1 To Len(str
InBlock.gifsStr 
= sStr & Mid(str, i, 1
InBlock.gif
If Mid(str, i, 1= "/" Then 
InBlock.gif
+= 1 
InBlock.gif
End If 
InBlock.gif
If j = 3 Then Exit For 
InBlock.gif
Next 
InBlock.gif
Return sStr 
ExpandedSubBlockEnd.gif
End Function
 
InBlock.gif
'将内容里的相对图片地址改成绝对地址的函数 
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Function formatHtml()Function formatHtml(ByVal str As StringAs String 
InBlock.gif
Return Replace(str"src=" & Chr(34& "/""src =" & Chr(34& formatURL(TextBox1.Text)) 
ExpandedSubBlockEnd.gif
End Function
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Private Sub TextBox1_Enter()Sub TextBox1_Enter(ByVal sender As ObjectByVal e As System.EventArgs) Handles TextBox1.Enter 
InBlock.gif
Try 
InBlock.gifthread 
= New Thread(AddressOf loadrss) 
InBlock.gifthread.Start() 
InBlock.gif
Catch ex As Exception 
InBlock.gif
MsgBox(ex.ToString) 
InBlock.gif
End Try 
ExpandedSubBlockEnd.gif
End Sub
 
ExpandedBlockEnd.gif
End Class

转自: http://www.cnblogs.com/aowind/archive/2005/03/16/119838.html

转载于:https://www.cnblogs.com/Dicky/archive/2005/03/17/122365.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值