MSHTML Area Map Click C# preferred

Posted on 2006-05-19
Last Modified: 2012-05-05
Sorry for the duplication but this question wasn't showing up in the 'Awaiting Answer' section.

Very simple .. Not for me but maybe for you.  I'm loose with my points.  Quick answers get sizable amounts.

Here is what I have:  I have a winform, browser control, 2 buttons.  One button logs in using button1_Click().  button2_Click() needs to do the following after I've logged in.

This is what I want:
I want to click on this areamap (programmatically).  I don't want to do a 'mousemove' type thing.  This is difficult for me because there is no standard Map/Area HTML.   I'm thinking I need to use the IHTMLAreaElement or something but don't know how to get to the href attribute.  This is what I have to work with.

<IMG height=140 alt="" src="images/somepic.gif" width=358 useMap=#somemap border=0>
<MAP name=somemap>
<AREA shape=RECT target=_blank alt="" coords=120,96,242,122 href="somelink.html">


By the way I'm logging in just fine to the previous page with code like this if anyone can use it:

private void button1_Click(object sender, System.EventArgs e) {
    try {
          IHTMLInputElement IhElementEmail;
          IHTMLInputElement IhElementPassword;
          IhElementEmail = (IHTMLInputElement)htmlDoc.getElementById("emailid");
          IhElementEmail.value = "";
          IhElementEmail.value = "someusername";
          IhElementPassword = (IHTMLInputElement)htmlDoc.getElementById("password");
          IhElementPassword.value = "";
          IhElementPassword.value = "somepassword";
          htmlDoc.parentWindow.execScript("void(signinuser());", "javascript");
    } catch(Exception exc) {
          MessageBox.Show("button1_Click: "+exc.Message);
Question by:famoso
    LVL 10

    Accepted Solution


    try this code to get the href attribute of AREA tag
    mshtml.IHTMLDocument3 document = (mshtml.IHTMLDocument3) axWebBrowser1.Document;
    mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection) document.getElementsByTagName("AREA");
    mshtml.IHTMLAreaElement areaElement = (mshtml.IHTMLAreaElement)collection.item(System.Reflection.Missing.Value, 0);

    Author Comment

    Thank you.  I will give it a try Monday.

    Author Comment

    Now how would I preform a programmatic click on that Area coordinates?

    Author Comment

    Or does the click need to be performed on the image that the map is associated with?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now