Painting on a WebBrowser control

A

abhimanyu

Hi,

I have an application written in C# that displays web page using the
System.Windows.Forms.WebBrowser control. I have overridden the
MouseDown method of this control and on mouse down I get the Html
element underneath the cursor and display its properties.

The problem is that when an element is clicked, I want to display a
border around the element for which I thought I will override the
OnPaint method and draw the border using element's coordinates.
Firstly the OnPaint was not being called, then I set the style to
UserPaint using
this.SetStyle(ControlStyles.UserPaint, true);
I now get the OnPaint call but whatever I draw is not visible on the
browser.

base.OnPaint(e);

if (_mouseDown)
{
e.Graphics.FillRectangle(Brushes.Blue, 0, 0, 100,
100);
_mouseDown = false;
}

I also tried overriding the WndProc and when the message is WM_PAINT I
draw using the Graphics object that I get using this.CreateGraphics()
but it didnt work either.

Any ideas??
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,

I have an application written in C# that displays web page using the
System.Windows.Forms.WebBrowser control. I have overridden the
MouseDown method of this control and on mouse down I get the Html
element underneath the cursor and display its properties.

The problem is that when an element is clicked, I want to display a
border around the element for which I thought I will override the
OnPaint method and draw the border using element's coordinates.
Firstly the OnPaint was not being called, then I set the style to
UserPaint using
this.SetStyle(ControlStyles.UserPaint, true);
I now get the OnPaint call but whatever I draw is not visible on the
browser.

            base.OnPaint(e);

            if (_mouseDown)
            {
                e.Graphics.FillRectangle(Brushes.Blue, 0,0, 100,
100);
                _mouseDown = false;
            }

I also tried overriding the WndProc and when the message is WM_PAINT I
draw using the Graphics object that I get using this.CreateGraphics()
but it didnt work either.

Any ideas??

Hi,

What you could do is modify the property of the element, and place a
border, in this way it's the webbrowser control the one responsible
for displaying the border
 
A

abhimanyu

Hi,

What you could do is modify the property of the element, and place a
border, in this way it's the webbrowser control the one responsible
for displaying the border

Thanks Ignacio !!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top