famoso
asked on
MSHTML mouseover events to identify html elements
I need code - C# preferrablly.
I have a WinForm, Browser Control and TextBox. I navigate to http://www.google.com/ when the form loads.
I would like the elements on the page to appear in the Textbox as I move the mouse over the webpage.
Examples:
As I move the mouse over the textbox on the Google page, in my WinForm Textbox should be something like:
Input
As I move the mouse over one of the buttons on the Google page, in my WinForm Textbox should be something like:
(Bad example but ... ) Input (I could get further if I had code to get me that far)
I would collect more info as in the case of the Button ie: Input - type=submit, etc.
I just need a nudge in the right direction. Anybody???
I have a WinForm, Browser Control and TextBox. I navigate to http://www.google.com/ when the form loads.
I would like the elements on the page to appear in the Textbox as I move the mouse over the webpage.
Examples:
As I move the mouse over the textbox on the Google page, in my WinForm Textbox should be something like:
Input
As I move the mouse over one of the buttons on the Google page, in my WinForm Textbox should be something like:
(Bad example but ... ) Input (I could get further if I had code to get me that far)
I would collect more info as in the case of the Button ie: Input - type=submit, etc.
I just need a nudge in the right direction. Anybody???
ASKER
Sumix, I love your work. I've seen it all over this site.
A problem I'm having is that there isn't a MouseOver for Document.
I have this:
void Document_MouseOver(object sender, HtmlElementEventArgs e) {
this.txtPageInfo.AppendTex t(e.ToElem ent.TagNam e+","+e.To Element.Na me); // etc.
}
private void axWebBrowser1_DocumentComp lete(objec t sender, AxSHDocVw.DWebBrowserEvent s2_Documen tCompleteE vent e) {
//MessageBox.Show("Documen t Really Complete");
try {
// The problem is the axWebBrowser1.Document doesn't let me have a MouseOver handler
// all I have is: Equals, GetHashCode, GetType, and ToString
axWebBrowser1.Document.Mou seOver+=ne w HtmlElementEventHandler(Do cument_Mou seOver);
// Initialize all the documents
htmlDoc=(HTMLDocument)axWe bBrowser1. Document;
htmlDoc1=(mshtml.IHTMLDocu ment)axWeb Browser1.D ocument;
htmlDoc2=(mshtml.IHTMLDocu ment2)axWe bBrowser1. Document;
htmlDoc3=(mshtml.IHTMLDocu ment3)axWe bBrowser1. Document;
txtAddressBar.Text=htmlDoc 2.url.ToSt ring();
txtPageInfo.AppendText(Sys tem.Enviro nment.NewL ine+"axWeb Browser1_D ocumentCom plete Fired");
getHeaders();
getHTML();
getForms();
getLinks();
getImages();
} catch (Exception ex) {
MessageBox.Show("axWebBrow ser1_Docum entComplet e: "+ex.Message);
}
}
A problem I'm having is that there isn't a MouseOver for Document.
I have this:
void Document_MouseOver(object sender, HtmlElementEventArgs e) {
this.txtPageInfo.AppendTex
}
private void axWebBrowser1_DocumentComp
//MessageBox.Show("Documen
try {
// The problem is the axWebBrowser1.Document doesn't let me have a MouseOver handler
// all I have is: Equals, GetHashCode, GetType, and ToString
axWebBrowser1.Document.Mou
// Initialize all the documents
htmlDoc=(HTMLDocument)axWe
htmlDoc1=(mshtml.IHTMLDocu
htmlDoc2=(mshtml.IHTMLDocu
htmlDoc3=(mshtml.IHTMLDocu
txtAddressBar.Text=htmlDoc
txtPageInfo.AppendText(Sys
getHeaders();
getHTML();
getForms();
getLinks();
getImages();
} catch (Exception ex) {
MessageBox.Show("axWebBrow
}
}
This is something I used to get the element at the location of the mouse. I made a timer and on every tick of the timer I got the element at the mouse location. It worked well but then I thought it would be better to get the element only when someone clicks. But you should try the timer idea. I don't have the code anymore so can't paste it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Does it make a difference that I'm using .NET 2.0 and the MSHTML WebBrowser?
No it shouldn't make a difference. Although I also used net 2.0 but I changed to using the WebBrowser control instead of the mshtml control. It is easier to use and get access to the HTML page properties. The same timer principle should work no matter which webbrowser control you use.
ASKER
Sumix, any ideas about my comment on 05/30/2006 11:19AM EDT???
Hello, famoso, thank you..
I have, indeed, used the webbrowser control and htmldocument class from 2.0 framework (System.Windows.Forms namespace, mouseover is an event of this HTMLDocument class). You should use those classes if you have .net 2.0.
ASKER
Sumix,
Although I would like to give the points to you, it doesn't seem I will be able to use that solution since I am using axWebBrowser1. Although I do need help on the following issue still withstanding. I got the href to the area but now I can't produce a click() event for it? Please read and help and I will award you points for it even if I need to open a separate question. Please let me know how you would like to handle it.
https://www.experts-exchange.com/questions/21857127/MSHTML-Area-Map-Click-C-preferred.html
Although I would like to give the points to you, it doesn't seem I will be able to use that solution since I am using axWebBrowser1. Although I do need help on the following issue still withstanding. I got the href to the area but now I can't produce a click() event for it? Please read and help and I will award you points for it even if I need to open a separate question. Please let me know how you would like to handle it.
https://www.experts-exchange.com/questions/21857127/MSHTML-Area-Map-Click-C-preferred.html
ok, i'll try to give you a hint for that question here since the other one was closed:
try
((mshtml.IHTMLElement)area Element).c lick();
as a note, if you have more items in the collection and you need to perform a click on a specific area you can identify it as in the response you got, only if AREA tag has a name attribute. Otherwise you need to loop through the collection using its Enumerator or a foreach loop, identify the desired Area and call a click method something like:
foreach (mshtml.IHTMLAreaElement areaElement in collection)
if (areaElement.href.EndsWith ("somelink .html")) // or any other way to identify the Area element
((mshtml.IHTMLElement)area Element).c lick();
hope this is of some help, no need points, maybe with another occasion
regards
try
((mshtml.IHTMLElement)area
as a note, if you have more items in the collection and you need to perform a click on a specific area you can identify it as in the response you got, only if AREA tag has a name attribute. Otherwise you need to loop through the collection using its Enumerator or a foreach loop, identify the desired Area and call a click method something like:
foreach (mshtml.IHTMLAreaElement areaElement in collection)
if (areaElement.href.EndsWith
((mshtml.IHTMLElement)area
hope this is of some help, no need points, maybe with another occasion
regards
ASKER
That worked. YOU ARE AMAZING. How can I get points to you??? Any way just let me know. Thank you OH WISE ONE.
I don't even know exactly, don't bother anyway, the fact you are so pleased worths much more for me
in form constructor:
this.webBrowser1.DocumentC
in webBrowser1_DocumentComple
void webBrowser1_DocumentComple
{
webBrowser1.Document.Mouse
}
in Document_MouseOver method you have acces to the hovered HtmlElement, you can retrieve any of its properties:
void Document_MouseOver(object sender, HtmlElementEventArgs e)
{
this.textBox1.Text = e.ToElement.TagName+","+e.
}