Web Browser Control

levyuk

Well-known member
Joined
Jun 7, 2004
Messages
313
Location
Wales, UK
Programming Experience
3-5
Guys I have a webbrowser control on my form. It contains a webpage with some information on it. What I want to do is for example. Highlight a link then click a button and get information about that link. I can get information about the tags but I don't know how to find out what part of the page is highlighted. If it helps you visulise what I mean, think about visual studio. When you click on a textbox the properties window automatically updates with information about that textbox. I want to be able to click a link and have a properties window automatically update with information about that link. Just like in Dreamweaver.

Any help would be briliant
Jon
 
Ok guys I can do this now but only in C#. It seems that there are differences between VB and C# in .net 2

This is how I do it in C# for anyone that cares
VB.NET:
[size=2][color=#0000ff]private[/color][/size][size=2][color=#0000ff]void[/color][/size][size=2] webBrowser1_DocumentCompleted([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, [/size][size=2][color=#008080]WebBrowserDocumentCompletedEventArgs[/color][/size][size=2] e)
{
 
[/size][size=2][color=#0000ff]this[/color][/size][size=2].webBrowser1.Document.Click += [/size][size=2][color=#0000ff]new[/color][/size][size=2][color=#008080]HtmlElementEventHandler[/color][/size][size=2](Document_Click);
doc = ([/size][size=2][color=#008080]HtmlDocument[/color][/size][size=2])[/size][size=2][color=#0000ff]this[/color][/size][size=2].webBrowser1.Document;
doc.Body.SetAttribute([/size][size=2][color=#800000]"contenteditable"[/color][/size][size=2], [/size][size=2][color=#800000]"true"[/color][/size][size=2]);
}
 
[/size][size=2][color=#0000ff]void[/color][/size][size=2] Document_Click([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, [/size][size=2][color=#008080]HtmlElementEventArgs[/color][/size][size=2] e)
 
{
 
[/size][size=2][color=#0000ff]if[/color][/size][size=2] (!([/size][size=2][color=#0000ff]this[/color][/size][size=2].webBrowser1.Document == [/size][size=2][color=#0000ff]null[/color][/size][size=2]))
 
{
 
[/size][size=2][color=#008080]Point[/color][/size][size=2] pt = System.Windows.Forms.[/size][size=2][color=#008080]Cursor[/color][/size][size=2].Position;
pt = PointToClient(pt);
pt.Offset(-[/size][size=2][color=#0000ff]this[/color][/size][size=2].webBrowser1.Left, -[/size][size=2][color=#0000ff]this[/color][/size][size=2].webBrowser1.Top);
 
[/size][size=2][color=#008080]String[/color][/size][size=2] sHTML = pt.ToString();
[/size][size=2][color=#008080]String[/color][/size][size=2] sText = pt.ToString();
sHTML = [/size][size=2][color=#0000ff]this[/color][/size][size=2].webBrowser1.Document.GetElementFromPoint(pt).OuterHtml;
sText = [/size][size=2][color=#0000ff]this[/color][/size][size=2].webBrowser1.Document.GetElementFromPoint(pt).OuterText;
textBoxText.Text = sText;
textBoxHTML.Text = sHTML;
}
}
 
[/size]
 
Back
Top