VB.Net如何设置对对象实例的对象引用? [英] VB.Net How to set an object reference to an instance of an object?
本文介绍了VB.Net如何设置对对象实例的对象引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用VB.NET,尝试将页面标题写入文本文件.我被困在这里:
Using VB.NET, trying to write a page title to a text file. I am stumped here:
Private Sub
Dim pagetitle As String
pagetitle = WebBrowser1.Document.Title
My.Computer.FileSystem.WriteAllText("page title.txt", pagetitle, False)
但是我收到一条错误消息:对象引用未设置为对象的实例."请帮忙!
But I get an error saying "Object reference not set to an instance of an object." Please help!
推荐答案
最有可能在Document
属性仍然等于Nothing
的情况下尝试访问它.将代码移到WebBrowser
控件的DocumentCompleted
事件中,如下所示:
Most likely you are trying to access the Document
property when it is still equal to Nothing
. Move your code to the DocumentCompleted
event of the WebBrowser
control, as such:
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If WebBrowser1.Document IsNot Nothing Then
Dim pagetitle As String
pagetitle = WebBrowser1.Document.Title
My.Computer.FileSystem.WriteAllText("page title.txt", pagetitle, False)
End If
End Sub
这篇关于VB.Net如何设置对对象实例的对象引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文