I am writing a c# winforms application which needs to enable its users to add content to its interface. I have looked at the RichTextBox and the WebBrowser controls, but I'm not sure which route to take. The content would contain text with newlines and several tags that will include images which are in the project resources.
This is my text [niceimage] and it
includes an image and another: [smiley]
The disadvantage of the RichTextBox control is that I would need to craft richtext by hand which I am not familiar with. Also the .net framework does not have the functionality to make Metafiles from Images, the format RTF uses for embedding images.
The problems I had with the WebBrowser is that I have no idea how to load a page via a stream. I tried the DocumentStream to no avail. Also I need to include images which would need embedded images in the html string, which might not be supported. Another issue is that the WebBrowser control might be too heavy as the control will appear in several places in the application. It als needs to load very quickly for the application to feel snappy.
You may want to look at the WPF RichTextBox which is supposed to be a major improvement over the .NET 2.0 version. Here's an article that elaborates upon the improvements.
Additionally, many Component development firms offer their own commercial version that has many feature and usability improvements. You may want to evaluate some of them, assuming that you are open to purchasing such a component. Try Googling for "RichTextBox component".
For the functionality that you require, I feel that using a WebBrowser (especially in multiple places in the application) would be overkill.
Related
I have to create a webbroswer in wpf that supports all the sites and scripts and play video , I have created but some site got crashed and not supporting .
Please provide solution.
What you ran into are probably error dialogs caused by JavaScript script errors. WPF WebBrowser control currently doesn't support disabling these dialogs and ignoring the errors. The WebBrowser control is based on Internet Explorer core and will have a hard time dealing with broken JavaScript, webpages will also sometimes report the web browser as old and inform the visitor about it, like FlipKart does.
One solution is to use WindowsFormsHost and host a Windows Forms equivalent - WebBrowser control - in it. The WF WebBrowser offers a property called SupressScriptErrors, which is not implemented by the WPF WebBrowser. That will hide the error dialogs for you, but you will still occasionaly receive a warning from the website saying they don't support the web browser used. That is out of your control unless you want to take a route of hacking the control to send a different User-Agent string and that will only fool broken UA detection, feature detection will still fail for things like HTML5 video, WebRTC and the like. More on this here.
You can also choose to embed Gecko (Firefox rendering engine) or Chromium. see here for more information on embedding alternative rendering cores as an alternative to IE COM wrapper offered by the framework.
Edit: this is also a possible solution, as it would seem. You will have to test it for yourself, though. I expect it to have less overhead than the WindowsFromHost element and although this uses reflection to develop against implementation, not interface, my opinion is it's safe to say the underlaying API in unlikely to change.
Update 2018 TL;DR; LaTEX for WPF
https://github.com/ForNeVeR/wpf-math
Original question
I need to have a way to draw a mathematical formula in Windows Forms or WPF. Some "FormulaTextBox" control would be exactly what I need.
I'm not asking about full implementation of LaTEX, but at least something beyond RichTextBox possibilities, with division lines, square roots, etc.
Here's a list of options, pulled from several webpages online, as well as a few similar questions on SO
WPF-Math, a WPF library for rendering math-related TeX markup.
gNumerator is a WinForms control that renders MathML. It is native C#, but appears to be quite old.
Math Expressions, a commercial WinForms control for displaying and editing math equations. Note: Not free
There's an unofficial port of JMathTex to a C# WPF control
The Windows version of the LaTex editor Lyx uses a native library called MikTex you could take a look at. I saw mention somewhere that the tex4ht package renders math equations to images
MimeTex/MathTex, as you already mentioned
You could also use a WebBrowser control, and just locally include one of many javascript libraries for rendering LaTex.
You could pawn off the work onto Microsoft Word (Example - requires users to have MS Word installed!)
Perhaps you can use the Wolfram Alpha API to retrieve the images.
If you want something beyond a RichTextBox abilities to render pie, divisions and sqr roots and etc, you could just use WebBrowserControl(s) as textbox's. Then to render formula's you could leverage techniques shown in this webpage, save it to your desktop and open the html file:
http://www.wjagray.co.uk/maths/ASCIIMathTutorial.html
Obviously you'll need a special syntax (or special calculator buttons) to enter the formula's and I'm guessing from looking at the customisations.js file driving that webpage that you could make your own list of operators and functions too.
Here's what I'd do if none of the .NET specific solutions work for you:
It's a bit hacky, but it'll work and your users won't know the difference. Download the Mathjax library. When your user enters in the equation, you could convert the equation to LaTex or MathML. You would then take the LaTex or MathML and generate an HTML file that references Mathjax and display the file in your tiny WebBrowser window (valid for both WinForms and WPF). This shouldn't require an internet connection.
Like I said, your users won't be any the wiser.
I have a desktop app build using .net. I want it to support multilanguages. I am able to do that using resources. Issue is what should I do for images which have text? Should I include all images for separate languages? If so then this will make it difficult and also will increase its size.
I just read that in Android there is "9 patch image", isn't there something similar?
I wish to add background image, and write text on top of that. This background image should resize without change in quality of the image automatically to the size of text in that language.
I couldn't think of any way to avoid separate images with WinForms. WPF, no problem. Web app, no problem. I played around with both text and image on a Button control, but that does not scale fully. I tried using a label over a PIctureBox, but it is impossible to achieve transparency with a Label control. I also tried this using a WebBrowser control--such a thing could possibly work, but would take some further research and would probably change your deployment dramatically (since you would need to make the localization available from some http server).
So I think there is no easy way to do this--I could find nothing easier than maintaining the images separately.
In one of my projects, i had text displayed on top of images. Since the site was multilingual, so no text was part of the images. Instead text was displayed on top of the images, using css properties for absolute position. This had to be tested in all browsers, with multiple languages, as the text size varies in each language, this might break the UI. so enough space has to be provided for text considering all supported languages
Update 2018 TL;DR; LaTEX for WPF
https://github.com/ForNeVeR/wpf-math
Original question
I need to have a way to draw a mathematical formula in Windows Forms or WPF. Some "FormulaTextBox" control would be exactly what I need.
I'm not asking about full implementation of LaTEX, but at least something beyond RichTextBox possibilities, with division lines, square roots, etc.
Here's a list of options, pulled from several webpages online, as well as a few similar questions on SO
WPF-Math, a WPF library for rendering math-related TeX markup.
gNumerator is a WinForms control that renders MathML. It is native C#, but appears to be quite old.
Math Expressions, a commercial WinForms control for displaying and editing math equations. Note: Not free
There's an unofficial port of JMathTex to a C# WPF control
The Windows version of the LaTex editor Lyx uses a native library called MikTex you could take a look at. I saw mention somewhere that the tex4ht package renders math equations to images
MimeTex/MathTex, as you already mentioned
You could also use a WebBrowser control, and just locally include one of many javascript libraries for rendering LaTex.
You could pawn off the work onto Microsoft Word (Example - requires users to have MS Word installed!)
Perhaps you can use the Wolfram Alpha API to retrieve the images.
If you want something beyond a RichTextBox abilities to render pie, divisions and sqr roots and etc, you could just use WebBrowserControl(s) as textbox's. Then to render formula's you could leverage techniques shown in this webpage, save it to your desktop and open the html file:
http://www.wjagray.co.uk/maths/ASCIIMathTutorial.html
Obviously you'll need a special syntax (or special calculator buttons) to enter the formula's and I'm guessing from looking at the customisations.js file driving that webpage that you could make your own list of operators and functions too.
Here's what I'd do if none of the .NET specific solutions work for you:
It's a bit hacky, but it'll work and your users won't know the difference. Download the Mathjax library. When your user enters in the equation, you could convert the equation to LaTex or MathML. You would then take the LaTex or MathML and generate an HTML file that references Mathjax and display the file in your tiny WebBrowser window (valid for both WinForms and WPF). This shouldn't require an internet connection.
Like I said, your users won't be any the wiser.
I've done a bit of looking around and found various bits and pieces relating to this, but nothing concrete.
I need to find a method of extracting UI elements other than that of the Spy++ tool. I'm able to locate screen items and their underlying text captions based on HWND, however 3rd party apps such as Firefox offer further problems as they only have one large window for the display. If anyone has any ideas on how to natively get screen coordinates to do an OCR or control recognition of UI elements within, say, a web page I'd love to hear from you.
If what you want programmatic access a web page as Firefox sees it, there are much better ways.
Try Watir or selenium. These are for testing web applications, and they allow you to problematically control the web browser.