Link to home
Start Free TrialLog in
Avatar of PhatFrogDev
PhatFrogDev

asked on

How can I use a webbrowser control as background of a MDI parent

I have created a C# winform MDI web browser based on some very helpful tutorials. I want to extend the functionality of this with the following items, but have no idea where to begin. If someone can help me with some code examples, I would be very appreciative.

Here are the things I'd like to do:

1. Use a webbrowser control in the background of the parent, and have the child windows appear over the top of this.

I want to have different backgrounds, HTML, etc., that can be easily changed without having to recompile. I tried this, but the child windows seem to be opening behind the webbrowser control. Any thoughts?

2. I would prefer each time a URL is entered into the Address field, a new child window is created. How do I force this? Currently they open in a new IE window.

3. Can I force a link that has target="_blank", or any command for a new window, to open in a child window, instead of launching an external IE window?

Thanks for any help you can offer.
Avatar of Rahul Goel
Rahul Goel
Flag of India image

See, you can do apply one approach that you can create a new webbrowser control on child form of the MDI. and size it to the lowest to lowest.. and you can attach event on that and put that control on the background of some visible control.
And you will keep the focus on the same child form
Avatar of PhatFrogDev
PhatFrogDev

ASKER

So I understand you correctly, are you saying I can create a maximized child form when the application is initialized, then use that as the background? Can the "background" child window be locked into place so it cannot be minimized, closed or moved?
Non-movable form:

http://vaibhavgaikwad.wordpress.com/2006/06/05/creating-a-immovable-windows-form-in-c/

That article talks about overriding WndProc.  You can use the same override to detect, and block other Windows messages, like WM_CLOSE.
Would it be better to extend the MDI Client and give it the features I wish to utilize? Is there an alternative to MDI that would enable me to accomplish the 3 items in my list?
As for extending the MDI Client, how would one do that, if it's even possible? Or, would that be creating a custom control based on the MDI Client?
What "3 items" are you talking about?  Are you asking for behavior of an MDI parent, without using a WebBrowser control?
Actually, I removed one of them, because if the 2 listed below can be done, then I can figure the rest out. I appreciate your time. The edited original question is below:

I have created a C# winform MDI web browser based on some very helpful tutorials. I want to extend the functionality of this with the following items, but have no idea where to begin. If someone can help me with some code examples, I would be very appreciative.

Here are the things I'd like to do:

1. Use a webbrowser control in the background of the parent, and have the child windows appear over the top of this.

I want to have different backgrounds, HTML, etc., that can be easily changed without having to recompile. I tried this, but the child windows seem to be opening behind the webbrowser control. Any thoughts?

2. Can I force a link that has target="_blank", or any command for a new window, to open in a child window, instead of launching an external IE window?

Thanks for any help you can offer.
May I be so bold as to ask what functionality that you are getting (or looking to get) from the WebBrowser, that you can't get a from a Form or PictureBox control?
Sure. I want to be able to display HTML, served locally or from a Web server. Now, if using a "locked" child window is the best way to do this, then so be it. But, it seems to me that would be kind of a hokey way to get the result. If not, then that's what I will do, and I can move on to the other item regarding the links and launching them in child windows.
If you want to render HTML to a page, I use a custom control that I can drag and drop from the ToolBox onto a form.
Ok. That would work, but I wasn't 100% clear, and I apologize. I would want the control to be able to render HTML, and Javascript, and CSS and anything that could be generated from server-side code as well. In other words, all the capabilities of a modern browser -- as far as rendering is concerned. This means, unless your custom control can do all that, I would need to use a webbrowser control based on IE, or Firefox, or WebKit.

Frankly, except for a few IE specific features, I really don't care which control I use.
Keeping in mind, of course, that all this needs to be happening in the background of a MDI Client, or some custom control that has MDI capabilities.
AND...each child window will also contain a webbrowser control...

I hope I'm being clear. Let me know if I'm not.
The source for the control came from Lutz Roeder's web site (if you know anything about Reflector):

http://www.lutzroeder.com/dotnet/

Writer
Writer is a simple editor for HTML files. Writer supports text layout and formatting, hyperlink editing and insertion of dates and pictures.

Writer.zip
C# source code attached through Experts-Exchange file storage site:

https://filedb.experts-exchange.com/incoming/ee-stuff/7699-HtmlControl.zip 
This control will not display Web pages from a remote Web server.
Also, it is throwing an error in VS 2008.

Error      1      Source file 'C:\Users\Kevin\Desktop\htmlcontrol\Properties\AssemblyInfo.cs' could not be opened ('Unspecified error ')      Common.RichTextEditor.HtmlControl
Hmmm...there should be a file reference in the project, which you can remove, and then add an AssemblyInfo.cs file back in.  I didn't realize that was in a sub-folder.  This control should display HTML text from a string, not a URL.
Well, I need the ability to display from a URL. There will be ocassions where the URL will have Javascript animations and effects, Flash, etc., so it has to be able to do these as well.
OK, that is more than just rendering HTML (I missed that requirement before), so you are back to the WebBrowser control.  

I believe that the Navigating event handler has a Cancel argument, that you can set to prevent the WebBrowser control from opening a new window.  That way you could create your own form with another WebBrowser control that you can navigate to that new URL.
Ok...I think we're getting somewhere, now. So, I use a "locked" child form with a webbrowser control to create the background. Then, I use the cancel argument to stop the webbrowser control from opening an IE window, and open one of my child forms instead. Do you have, or know of somewhere that may have some example code I can see?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How could I determine what the target of the link is?
i.e. target="_blank", or whatever.

If there isn't a target, or some function that opens a new window, I would want the link to simply go to the URL in the same child window.