troubleshooting Question

Bounds of a control

Avatar of levyuk
levyuk asked on
7 Comments1 Solution385 ViewsLast Modified:

I have a webbrowser control and when a user clicks on an item on the page in the webbrowser control it will display some info about the element that is clicked. The is handled in this code.

        void doc_Click(object sender, HtmlElementEventArgs e)
            if (webBrowser.Document != null)
                pt = System.Windows.Forms.Cursor.Position;
                pt = PointToClient(pt);
                pt.Offset((-webBrowser.Left - splitContainer2.Panel1.Width), (-webBrowser.Top - statusStrip1.Height - menuStrip1.Height - toolStrip1.Height));
                Rectangle rc = new Rectangle(webBrowser.Location, webBrowser.Size);
                if (rc.Contains(pt))
                    element = (HtmlElement)document.GetElementFromPoint(pt);

        //Gets the current elements info
        void getElementInfo(HtmlElement element)
                textBoxLink.Text = (String)element.GetAttribute("href");
                textBoxWidth.Text = (String)element.GetAttribute("width");
                textBoxHeight.Text = (String)element.GetAttribute("height");
                comboBoxTarget.SelectedItem = (String)element.GetAttribute("target");
            catch (Exception)
                toolStripStatusLabel.Text = "An error occured";

The problem that I have is that if I click on an image then it doesn't always display the details. I.e. if I click on the bottom right of the image it wont display the details but it will if I click on the top left. How can I make it so that I can click anywhere on the image and display it's details? Image is just an example btw
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros