Tôi gặp sự cố khi cố lấy tiêu đề tài liệu từ Trình duyệt web trong C#. Nó hoạt động tốt trong VB.NET, nhưng nó sẽ không cho tôi bất kỳ thuộc tính nào trong C#.C#: Làm cách nào để lấy tiêu đề tài liệu từ phần tử WebBrowser?
Khi tôi nhập MyBrowser.Document., các tùy chọn duy nhất tôi nhận được là 4 phương pháp: Bằng, GetHashCode, GetType và ToString - không có thuộc tính.
Tôi nghĩ rằng đó là vì tôi phải gán tài liệu cho một cá thể mới trước, nhưng tôi không thể tìm thấy lớp HTMLDocument tồn tại trong VB.NET.
Về cơ bản những gì tôi muốn làm là trả lại Document.Title mỗi khi Trình tải trang web tải/tải lại trang.
Ai đó có thể giúp bạn không? Nó sẽ được nhiều đánh giá cao!
Đây là mã tôi có vào lúc này ...
private void Link_Click(object sender, RoutedEventArgs e)
{
WebBrowser tempBrowser = new WebBrowser();
tempBrowser.HorizontalAlignment = HorizontalAlignment.Left;
tempBrowser.Margin = new Thickness(-4, -4, -4, -4);
tempBrowser.Name = "MyBrowser";
tempBrowser.VerticalAlignment = VerticalAlignment.Top;
tempBrowser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(tempBrowser_LoadCompleted);
tempTab.Content = tempBrowser; // this is just a TabControl that contains the WebBrowser
Uri tempURI = new Uri("http://www.google.com");
tempBrowser.Navigate(tempURI);
}
private void tempBrowser_LoadCompleted(object sender, EventArgs e)
{
if (sender is WebBrowser)
{
MessageBox.Show("Test");
currentBrowser = (WebBrowser)sender;
System.Windows.Forms.HtmlDocument tempDoc = (System.Windows.Forms.HtmlDocument)currentBrowser.Document;
MessageBox.Show(tempDoc.Title);
}
}
Mã này không cho tôi bất kỳ lỗi nào, nhưng tôi không bao giờ thấy MessageBox thứ hai. Tôi thấy cái đầu tiên mặc dù (thông báo "Test"), vì vậy chương trình đang đi tới khối mã đó.
Bạn cần một dàn diễn viên làm HTMLDocument. – Mau
Vui lòng cho chúng tôi biết mã của bạn. – SLaks