ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

C# Help Pls :)

(1/2) > >>

KynloStephen66515:
Anybody got any clue how to do the following in Visual C# 2010

When working with richTextBox I would like to be able to output a live preview into a popup form, or same-form object.

This should initially be able to handle HTML code from the 'RTB' and coded to refresh after every statement is closed (IE: <br />)

Obviously manual refresh and such buttons would be required.

The second option around this is to simply have a webBrowser object load a requested .html/.php etc. file.

To do it this way, I would be having a form open, and using onLoad I would be calling an openFileDialog so the user can select the file. 

Not asking for anybody to completely code either, just maybe a push in the right direction, or even an MSDN link :P  This is one of the major functions of the NANY project ive been working on for some time now, and would like to be able to have it come to life in time for NANY!

It would be a massive advantage if the live preview window handled mouseover events and highlighted the code in the 'RTB' for the object the user is hovered over ((IE, if a user hovers over a navigation link called 'Home' the 'RTB' window will automatically navigate to the correct segment in the code, and highlight '<a href="index.html">Home</a>')) <---- Not a massivly required function for the moment and I could probably figure this part out myself after a while!  Although, a little hint wouldnt hurt! ^_^

Thanks in advance,

Stephen

f0dder:
Two relevant SO questions:

http://stackoverflow.com/questions/150014/load-in-memory-text-into-webbrowser-control
http://stackoverflow.com/questions/790542/replacing-net-webbrowser-control-with-a-better-browser-like-chrome

Renegade:
I'm not sure I understand what you're trying to do...

Does this help?

http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx

http://www.codeproject.com/KB/edit/HtmlEditor.aspx

http://www.codeproject.com/KB/miscctrl/HtmlEditor.aspx

Checking in there, they're using the MSHTML library... Ahem... If you've ever used shdocvw.dll and MSHTML, you know it's horrible.

I've got a basic tutorial written up here for some aspects of it:

http://renegademinds.com/TipsTricks/DevelopersCorner/WebFormSubmitter/tabid/82/Default.aspx

The WebBrowser control in Visual Studio is just those two ruffians wrapped up. For highly controlled situations inside of your application, they're good. However, if you actually need to do HTML that will be used outside of your application, or consume HTML from outside of your application, then you have a potential problem.

Since it's basically just IE 6, you have all kinds of baggage there. If a web page is using hacks like PIE, you could be in big trouble. The hacks that PIE uses are IE6 filters (I think they started in 5.x though, not sure), which are highly CPU intensive. If there's much going on there, then it will grind IE6 to a halt. Not good. Besides, IE6 is just plain slow anyways.

You might want to look into those links above that f0dder posted. Check out MozNet for sure. I've used the old GeckoFX control, and it's wonderful. I bought a MozNet license but haven't had time to use it quite yet. It's dirt cheap too. (I bought early, so I got a small discount, but it's still cheap.)

I checked out this quickly:

http://awesomium.com/

And it does look awesome. :)

If you can post a bit more about what you're trying to do, maybe I can help some more.

Opening and loading HTML into the browser is pretty simple though.

WebBrowser.Navigate(fullPathToHtmlFile);

For loading in memory, use wbr.DocumentText > http://stackoverflow.com/questions/150014/load-in-memory-text-into-webbrowser-control

However, keep in mind that the DocumentCompleted event fires 3x per page, and isn't predictable/reliable. So you'll need to use the Navigated event, but some things will only work in DocumentCompleted... Welcome to Hell.


Does any of that help or is it relevant?




KynloStephen66515:
If you can post a bit more about what you're trying to do, maybe I can help some more.
--- End quote ---

It just basically needs to be a live preview of code written in a richTextBox

WebBrowser.Navigate(fullPathToHtmlFile);
--- End quote ---

I understand this part as that very basic but what it needs to do is navigate to the loaded HTML file selected from a openFileDialog so I figured the code would be more along the lines of:

webBrowser1.Navigate(selectedFile);


Two relevant SO questions:
--- End quote ---

Cant check links right now, but will look ASAP! Thanks

Check out MozNet for sure. I've used the old GeckoFX control, and it's wonderful. I bought a MozNet license but haven't had time to use it quite yet. It's dirt cheap too. (I bought early, so I got a small discount, but it's still cheap.)
--- End quote ---

Im not dead set on using the standard IE engine that comes with visual c# but im somewhat stuck with it right now as im using a machine with no internet connection, so figured I would try at least get the basic functions down.

In the project im doing, im using Syntax Highlighting, (Smart)AutoCompletion and a selection of other features that I feel will make it run a lot better and be a lot more usefull in the future.

Im also sort of re-inventing the wheel with the project in itself as theres no real shortage of software to do some of the things im adding into mine, but I have yet to find one that actually offers them all in one simple window, without having to download 6 seperate suites to do it!  Its an adaptation of several earlier projects of mine that I was using as a starting point to learn about the things I needed for this.  Still want to bang my face on the desk  :wallbash: when implementing (Smart)AutoComplete but its getting there.

Renegade:
webBrowser1.Navigate(selectedFile);
--- End quote ---

webBrowser1.Navigate(openFileBrowser1.FileName);

Is that what you need?

For live updates, you can use the change events... but it might get ugly. Especially with the IE engine. It's just slow.

Do you really need a live update? You might want to go the MSHTML route then as you can set it to edit mode and do LIVE edits right in the browser. There's code out there to show you how to do it. Search for "html editor mshtml" and you should find something that does something like what you're looking for, if not exactly.

Navigation

[0] Message Index

[#] Next page

Go to full version