Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
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 8-Oct-12 8:48am
Comments
Kschuler at 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 at 8-Oct-12 14:17pm
   
Error messages, no kidding? Apparently, OP did not start, needs introductory ideas. I actually answered, please see.
--SA
narendrankg at 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 at 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 at 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
Kschuler at 8-Oct-12 14:19pm
   
I don't know why it wouldn't paste into a textbox control, unless you used more than one line of text and your textbox control only supports one line. Or are you saying that you want to paste the function and also have it actually calculate? Please describe in greater detail what you want to happen when you paste into the textbox.
Sergey Alexandrovich Kryukov at 8-Oct-12 14:52pm
   
Why? Because TexBox does not support it, period.
--SA
Kschuler at 8-Oct-12 15:00pm
   
Textbox doesn't support copy/paste?...um...I've gotten a textbox to support copy/paste before.
Nelek at 8-Oct-12 15:05pm
   
Sergey is telling you that Copy/paste of mathematical expressions is not possible. plain text is not the same
Kschuler at 8-Oct-12 15:09pm
   
He explains it more in his solution...it depends on how they are writing the mathematical equation. If they use plain text it's fine but if they are using mathematical notations, then there are issues. I just assumed that we were talking plain text all along and thought Sergey was saying the textbox doesn't support copy/paste.
Kschuler at 8-Oct-12 15:18pm
   
Also...I'm not the original poster.
Nelek at 9-Oct-12 11:51am
   
I know, I corrected it some minutes after
Sergey Alexandrovich Kryukov at 8-Oct-12 16:06pm
   
Right. I never said Paste is impossible, but the result of the Paste will be reduced to plain-text version of the content used in Copy, because TextBox does not support anything else. This is how Clipboard works across different data types.
--SA
narendrankg at 8-Oct-12 14:29pm
   
I didn't want to calculate that expression i just need such control where i can write any mathematical equation with any function.
Sergey Alexandrovich Kryukov at 8-Oct-12 14:49pm
   
This is easier, and this is the only aspect I discussed in my answer.
--SA
narendrankg at 8-Oct-12 14:34pm
   
Suppose a maths teacher has a file with such questions that contain such square root, square or subscript sign. Or you can suppose a chemistry equation. Then how will he be able to post that in his blog or in his website.?
Sergey Alexandrovich Kryukov at 8-Oct-12 14:51pm
   
A Web site is a different issue. You can assume MathML is supported or not. It's not supported by all engines. If you want to make is really universal, you need to render graphics in some bitmap on the server side and publish the bitmap using the <img> tag. This is how Wikipedia works. There are special engines to do such things.
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Comments
Nelek at 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 at 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 at 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)

  Print Answers RSS
0 DamithSL 295
1 OriginalGriff 214
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 113
0 OriginalGriff 7,760
1 DamithSL 5,874
2 Sergey Alexandrovich Kryukov 5,444
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100