Click here to Skip to main content
12,699,351 members (33,081 online)
Rate this:
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
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?
Error messages, no kidding? Apparently, OP did not start, needs introductory ideas. I actually answered, please see.
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?
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.
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.
Kschuler 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.
Why? Because TexBox does not support it, period.
Kschuler 8-Oct-12 15:00pm
Textbox doesn't support copy/paste?'ve gotten a textbox to support copy/paste before.
Nelek 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 8-Oct-12 15:09pm
He explains it more in his 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 8-Oct-12 15:18pm
Also...I'm not the original poster.
Nelek 9-Oct-12 11:51am
I know, I corrected it some minutes after
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.
narendrankg 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.
This is easier, and this is the only aspect I discussed in my answer.
narendrankg 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.?
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.

1 solution

Rate this: bad
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:[^].

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,[^]). Hence, you would probably need to use some third-party library for .NET, such as Mozilla Gecko:[^].

Please see what's currently supported by major existing layout engines:[^].

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.

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.
Thank you very much for pointing out my mistake. This is exactly it; I fixed the link to the comparison of layout engines.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2017
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