C# WinForms: Should I use a web browser control - c#

I am building a windows forms application that I will be adding a control within that will display quite a bit of different data. For the most part the data inside will be navigation buttons and help/training text.
I think it would be ideal if I could write the contents in HTML and then just display that in the control in the application, but I am not sure if this is a good idea.
Another point to note is there will be a web based version of the same application at some point in the near future, and doing this part of the application in HTML will make for very easy reusability.
The users will not have IIS installed, if this matters.

For this purpose, I think that an embedded web browser would be absolutely great. Alot of applications use a web browser control for navigation, information, training, etc. Steam is one example. In addition, reusability is almost always a best practice.
But I would use WebKit instead of the built-in IE web browser control.

I have a similar application and I think the WebBrowser control works very well. If you think it's what you need, I would for it and there's many other applications that do something similar. You can call Javascript functions in the HTML page from C# using HtmlDocument.InvokeScript(), and C# from Javascript using window.external and having this two-way communication makes life simple.
Users do not need IIS installed as you're not running a web server, just displaying content using HTML.
I would go for the built-in IE control rather than webkitdotnet to be honest. Although WebKit itself is superior to IE, the webkitdotnet project at version 0.5 it doesn't have the C#<> JavaScript communication or DOM access and it seems hard to tell if it's still being actively developed. It'll be great if/when it gets feature parity as IE is obviously far from perfect, but the advantage of the built-in IE control is every user of your app will have it already installed and the WebBrowser control is well tested. There are some disadvantages I've found:
IE versions may range from 6 to 9, so you'll to test to make sure your content works in all (as with a website).
There's a bug in IE (at least up to 8) that relative links do not work in combination with a <base href="file://...">. This can stop you being able to use relative links in your local HTML documents.
Sometimes pages display differently inside the WebBrowser control than they do out of it. For instance, http://bugs.jquery.com/ticket/7104 is one and I've come across another similar bug affecting cufon.
For compatibility reasons, even if your users install IE > 7 the WebBrowser control will still render your content in IE7 rendering mode by default. This is different to standalone IE which renders in the most-standard mode by default, so it can catch you out if you're not expecting it. You can change this by adding <meta http-equiv="X-UA-Compatible" tag if you want, though I actually found it makes life easier as it reduces the amount of different versions you've got to test against.

Related

Creating web browsers

From what I know, browsers that are based on WebKit have been built around the open source webkit project after they downloaded it and built it, so if one were to build a browser around the Trident rendering engine/Internet Explorer's rendering engine, would you-
Download Trident from somewhere, build it and add it to your project, or;
Add a System.Windows.Forms.WebBrowser Control to your Form and use that?
I believe that the System.Windows.Forms.WebBrowser control is indeed based on IE's Trident engine. however it is highly limited in what it can and can't do, by default.
You can however modify application specific settings for your browser to enable features through the control.
An example of this is that the WebBrowser control, by default, renders using the lowest setting supported by the version of IE installed on the machine, so for example if you have IE9 installed, the WebBrowser control will render in IE7 compatibility mode, but you can make it render using IE9 standards based mode if you change/add some settings to the registry.
Take a look at implementing/modifying Internet Feature Controls here:
http://msdn.microsoft.com/en-us/library/ee330720%28v=vs.85%29.aspx
On another note, I think you'd be hard pushed to find a download for Trident. Being a Microsoft product, my guess is that it's a closely guarded, closed source, secret! - However of you do find a download for it, I'd be very interested to know more! :-)

Alternative WebBrowser .Net C#

I have some problem using default WebBroswer with C#.
I'm making program in C# WindowsForm. I would have multiple "tabs" of "Broswer" and i need to change many things like UserAgent .
I had problem to do this with default WebBrowser becouse the trick(found on stackoverflow) worked only for 1 page and dont for all session.
Olso i need JavaScript support.
My Question is :
Is there another webBroswer that emulate multiple "tabs" of webBrowser , support javaScript (This is very important : i need disable Javascript for a website page that have Location Header ), and that it's possible change UserAgent and so emulate all existing Browsers ?
If answer it's not What kind of "real" browser could i use with My c# WinForm Program?
Regards
Edit: I already used GeckoFX but without good result (with JavaScript)
You could try awesomium.
You'll have to write some code yourself (including tabs) as it's just a framework.
However, I haven't come across anything on for .net that comes close and it should meet your requirements.
There is a free license for "Indie Companies" (if you made less than $100k), non-commercial use or evaluation & dev purposes.
Downside is, you wont get access to the source for free, I don't know if that's a deal-breaker for you or not.
Pricing

Possible to render html in a compact edition mobile 6 phone form?

I am wondering does anyone know if it is possible to render html in a mobile 6 form? The only way I can think that may work is the internal web browser control.
I am wondering is there a better way? I am thinking if I go the path of web browser control I will have to generate an html file then insert the code I want into this file.
I need something like this because I am pulling in some text that can possibly be formatted with html stuff such as font weight.
A Browser Control is really the only way (unless you want to parse the HTML yourself and turn it into rich text for an RTF control, or worse, manually handle it all yourself).
As people have said you do need 2 controls, but it might be possible to hide the regular textbox (maybe behind the browser control) will still leaving it editable.
In this case although it would be controlled underneath with code like <b>mytext</b>, the user would never see that giving them some illusion of a WYSIWYG editor (though I can already imagine a few problems you might come into attempting this)
I have written an HTML edit control for .NET.
It doesn't currently support Windows Mobile: but I have Windows Mobile development experience myself, and I might be able to port it to the Compact Framework, if you would be willing to pay for that, as explained in the Developing New Functionality section.

Tracking actions in a browser component

Im a c# developer and I believe that what I want to achieve is going to move out of the realms of some drop in .NET component so I am looking for advise on what I use externally which .NET can inter op with.
My requirements are to have an embedded web browser control in a WPF/Winforms applciation BUT I will also need to keep track of the following:
User interaction i.e. what pages they visit, forms submitted where they click etc.
DOM manipulation and traversing
I am guessing here but it seems that I might need to start looking at open source html/web browsers out there like WebKit etc. Is this the right track or is there anything currently available in the form of a control/COM object that I can use directly.
Cheers, Chris.
You should be able to accomplish point 1 using the webbrowser control in Visual Studio, but I dont think DOM manipulation is available, i do know you can traverse all the tags.
reference

c# hosting a usercontrol in IE

Our web page is only available internally in our company and we am very intrested in being able to offer interactive .net usercontrols on our departments website in the .Net 2.0 enviorment. I have been successful with embeding the object as so:
<object id="Object1" classid="http:EmbedTest1.dll#EmbedTest1.UserControl1"
width="400" height="400">
<param name="TestStr" value="Test Param String" />
</object>
The control worked just fine and the value was passed to the control without issue.
But I had a problem with passing subsequent values back to the embedded control
attempt to Recieve event from control:
attempt to update control:
<script type="text/javascript">
function UpdateStr()
{
Object1.Text = "update string";
}
</script>
Reference:
http://www.15seconds.com/issue/030610.htm
http://windowsclient.net/articles/iesourcing.aspx
Questions:
Is this technology outdated? - if so is there a replacement
Should I just work with action script instead of trying this?
I have got this to partially work and I was attempting to connect to a webservice that I have running and I got many security exceptions...I didn't get the same exceptions when I used action scipt2 in the same manner?
(side note : - how do i paste html script examples?)
Thanks.
Brad
Not out-dated so much as rarely used, and IE-only. If you want web-like deployment for desktop apps, use ClickOnce. If you want C# code that runs in the browser without security issues, use Silverlight. You could also look at XBAPs, which are sandboxed WPF apps that run in the browser, works on IE and Firefox, but requires the full .NET to be installed client-side, whereas Silverlight does not have this problem. Bottom line: look at Silverlight.
That's certainly an option. If you're more familiar with the Microsoft stack, you should try Silverlight, where you can code C# against a subset of the .NET framework right inside the browser.
We've used .NET controls in web pages internally and had a wide variety of strange issues, mostly related to scripting or security. Hard to determine the problem without more information.
p.s. write all code examples using the <pre> tags. There's a "code sample" button on the toolbar.
If the things that you are doing with the Windows Controls could be done with ASP.NET web controls instead, I recommend that you consider switching. You'll have much better control over the exchange of info from the client to the server.
1, 2) Yes it is outdated. If you want to work in .NET (and you're bent on having a control rather than an ASP.NET-style page/site), give Silverlight a try instead.
3) .NET code running in the browser is subject to very strict security controls (can't call back to a web site it didn't come from, for example).

Categories