Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
I want to right or copy-paste mathematical function or expression in a text box control. If user defined control can be used then also tell of how? Moreover i want to store that mathematical equations/function in database.
Thanx a lot
Posted
Comments
Kschuler 8-Oct-12 13:53pm    
What have you tried so far? What code do you have and what about it isn't working? Are you getting error messages?
Sergey Alexandrovich Kryukov 8-Oct-12 14:17pm    
Error messages, no kidding? Apparently, OP did not start, needs introductory ideas. I actually answered, please see.
--SA
narendrankg 8-Oct-12 14:08pm    
Suppose you have written any mathematical equation with some mathematical function in wordpad. Now when you try to copy this and paste it into a textbox control in .net then it does not happen so. So now i need a control where i can paste this and also need to store that expression in database?
Sergey Alexandrovich Kryukov 8-Oct-12 14:18pm    
Wordpad is not advanced enough for such things, practically, not a big advancement compared with plain text. And TextBox is nothing but plain text at all. Please see my answer for detail.
--SA
Sergey Alexandrovich Kryukov 8-Oct-12 14:19pm    
And please don't comment on your questions as "solution". It will be removed; no one will be notified. You need to use "Improve question" above; you can also comment on existing posts.
--SA

1 solution

The text box control, whatever it is, is not designed for presenting anything but plain text.

You may choose to use only the notation traditional for high-level programming language, to write expressions in the plain text form (example: "sqrt(sin(x))"). If you want require your customer to be able to learn and use such notation, it can be fine, but if you assume that the customer does not have to be comfortable with programming style of writing but is familiar with traditional mathematical notations as they are presented in books, you will need to solve much more difficult problem.

One step forward would be using simplified notation with added subscript/superscript expressions not not all those integrals, horizontal-line division notation, radical signs, etc., you can use HTML. Then, you have two ways to represent them: WebBrowser control (I'm not giving you the full type name because you did not specify the UI library you want to use) or some structured-text control, such as RichTextBox (in WPF, there are more options). The input of such data is the separate problem, pretty difficult, but just for presentation, I could advice wonderful HTML-based controls presented in these CodeProject articles:
A Professional HTML Renderer You Will Use[^],
WPF HTML Supported TextBlock[^].

A full-fledged option would be the support of MathML. See also how the problem of embedding of MathML looks like:
http://en.wikipedia.org/wiki/MathML[^].

Using it would be even more difficult problem, even for just presentation. One option would be using MathML directly embedded in HTML, but this is a feature of HTML5 not yet supported by all browsers. Importantly, at the moment of writing, to best of my knowledge, it is not supported by IE which control will actually be used it you use the WebBrowser control provided in the GAC as a part of .NET FCL (Framework Class Library, http://en.wikipedia.org/wiki/Framework_Class_Library[^]). Hence, you would probably need to use some third-party library for .NET, such as Mozilla Gecko:
http://en.wikipedia.org/wiki/Gecko_%28layout_engine%29[^].

Please see what's currently supported by major existing layout engines:
http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28HTML5%29[^].

I don't even discuss how can you implement the input of the formulas. It will need serious design and development work, really costly in terms of working hours of really qualified developers.

Finally, you can develop your own custom control with your own rendering and input, based directly on the Control class (please see my note on the unknown UI library to be used). Think by yourself if it seems feasible or not.

—SA
 
Share this answer
 
v2
Comments
Nelek 8-Oct-12 14:42pm    
You repeat the wikipedia link about "Gecko", is it on purpose or just a copy paste error?

BTW, nice answer.
Sergey Alexandrovich Kryukov 8-Oct-12 14:47pm    
Thank you very much for pointing out my mistake. This is exactly it; I fixed the link to the comparison of layout engines.
--SA
Nelek 8-Oct-12 14:48pm    
You are welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900