Hi!!!!!!!
I have made a window application in which i am entering mathematical equations and side by side the corresponding math format is generated like we see in books.
In this, I am using LATEX/MimeTEX for generating math format and it uses special symbols for generating math format.
Like for square root ,we use "\sqrt" , for divide symbol we use "\div" , for fraction we use "\frac" and so on .The complete list of symbols can be seen on following link:
http://www.forkosh.com/mimetextutorial.html
Now, i want to make it more user friendly in such a way that when user clicks on divide button then a divide sign should appear like "÷" but in coding it should implement "\div" and generate the coresponding math format.Similarly for fraction ,in the textbox there should appear "()/()" and in background it should implement "\frac {}{}".Similarly for other functions also such text should appear in textbox which user can understand easily but in ocding it should implement the symbols which mimeTex can understand.
Can anyone give me the solution for this.............
Loading
Danatas GerviPosted Oct 6, 2009, 8:24 AM
But what the problem to write the code of own contain method?
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox userInput = sender as TextBox;
if (userInput != null)
{
int indexOfLast = m_InsertedOperators.Length;
int charsOfNext = userInput.Text.Length - indexOfLast;
string nextOperator = userInput.Text.Substring(indexOfLast, charsOfNext);
if (OperatorIsLegal(m_OperatorsFiles.Keys, nextOperator))
{
m_InsertedOperators = userInput.Text;
GetImageByKey(nextOperator);
}
}
}
private bool OperatorIsLegal(Dictionary<string, string>.KeyCollection keyCollection, string nextOperator)
{
foreach (var existKey in keyCollection)
{
if (existKey == nextOperator)
{
return true;
}
}
return false;
}
richa jainPosted Oct 8, 2009, 2:00 AM
Thanks for your reply...........
richa jainPosted Oct 6, 2009, 3:34 AM
Gaurish KumarPosted Oct 6, 2009, 2:15 AM
Change this line to your code
if (m_OperatorsFiles.Keys.Contains(nextOperator))
to
if (m_OperatorsFiles.ContainsKey(nextOperator))
Hope it will help.
richa jainPosted Oct 6, 2009, 12:59 AM
But I am getting following error:
'System.Collections.Generic.Dictionary
Danatas GerviPosted Oct 5, 2009, 7:44 AM
Ok.
As I understand, you want to get correct image filename when user inserts a key of operation, and display this image on form?
If so (one direction search), better to use Dictionary.
namespace ShowOperatorPicture
{
public partial class Form1 : Form
{
Dictionary<string, string> m_OperatorsFiles;
string m_InsertedOperators = "";
public Form1()
{
InitializeComponent();
// lets fill our dictionary - correct and add all neded values here.
//(tip - '@' before string allow to type any characters)
m_OperatorsFiles = new Dictionary<string, string>();
m_OperatorsFiles.Add(@"\div", "divide.gif");
m_OperatorsFiles.Add(@"\rem", "minus.gif");
m_OperatorsFiles.Add(@"\add", "plus.gif");
m_OperatorsFiles.Add(@"\mult", "asteriks.gif");
m_OperatorsFiles.Add(@"\sqr", "squareRoot.gif");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox userInput = sender as TextBox;
if (userInput != null)
{
int indexOfLast = m_InsertedOperators.Length;
int charsOfNext = userInput.Text.Length - indexOfLast;
string nextOperator = userInput.Text.Substring(indexOfLast, charsOfNext);
if (m_OperatorsFiles.Keys.Contains(nextOperator))
{
m_InsertedOperators = userInput.Text;
GetImageByKey(nextOperator);
}
}
}
private void GetImageByKey(string nextOperator)
{
// here i simple add filename to label on form (only for checking the logic of event)
// but you shoud use your method WriteEquation(string equation) to get real image
if (nextOperator != "")
{
string filename = m_OperatorsFiles[nextOperator];
label1.Text += filename + " ";
}
}
}
}
On the form – only label (it will be picture box on your form) and text box.
On designed I have added event handler "TextChanged" for this text box.
This is only example, how to use simple collection.
richa jainPosted Oct 5, 2009, 1:56 AM
Actually I am not much familiar with the LINQ so i am not able to use it properly.
In my application there is a toolbar(to enter user friendly text because user cannot get all operators on keyboard) ,
a textbox( to enter string and operators) , and a picture box in which math format is displaying .
And when user is using toolbar then each symbol is appended in textbox and I want to create math format for each appended symbol.
For text_changed event I using following code:
Kindly help me how to use your code as I am taking input from textbox and for each appended symbol I have to generate math output.......
Danatas GerviPosted Oct 4, 2009, 4:40 AM
This is not so proper use of regular extension…. I think that regex is designed for working with potential unknown text….
If you do know all text on level of writing the code – you can use structural objects…. Use dictionary (Dictionary), as Roei
Bar says, or my suggestion…
richa jainPosted Oct 2, 2009, 8:08 AM
Actually I used the concept of regular expression but I am not getting the desired output.
But the problem is that , since the text which is appended in textBoxEquation is "()/()" which is user friendly and in output I want the fraction form like in books.....But i am getting bracket values only.
How to modify my code..........
Kindly help me and provide me the solution.............
Danatas GerviPosted Oct 1, 2009, 8:02 AM
You can use two dictionaries, where keys for one – is value to another…
But, because of little qtty of your operators (200? 300?)
Look at this as variant:
public void TestOperators()
{
List<UserMathPair> AllOperators = new List<UserMathPair>();
AllOperators.Add(new UserMathPair()
{
Operator = "****",
UserFrendly = "do not know"
});
AllOperators.Add(new UserMathPair()
{
Operator = "[][][]",
UserFrendly = "do not know"
});
AllOperators.Add(new UserMathPair()
{
Operator = @"\\\\\\\",
UserFrendly = "+++"
});
AllOperators.Add(new UserMathPair()
{
Operator = "div",
UserFrendly = "//"
});
AllOperators.Add(new UserMathPair()
{
Operator = "multiply",
UserFrendly = "*"
});
// and use linq to find what you need:
string userFrendly = "*";
var opValue = from eachOp in AllOperators
where eachOp.UserFrendly == userFrendly
select eachOp.Operator;
string opString = opValue.FirstOrDefault();
userFrendly = "empty";// lets erase hardcoded value ("*");
var userOp = from eachOp in AllOperators
where eachOp.Operator == opString
select eachOp.UserFrendly;
userFrendly = userOp.FirstOrDefault();
//userFrendly == "*" again
}
}
public class UserMathPair
{
public string Operator;
public string UserFrendly;
}
richa jainPosted Oct 1, 2009, 12:16 AM
Thanks for your reply............
Can give me an example for how to implement it......
Roei BarPosted Sep 30, 2009, 3:22 PM
like a KeyValuePair
then you will run on the Text and do a replacment for every Key to the value
and during calculation do it in reverse