i want that use Enter as '=' but i try to run this code but not solve problem.
please help me about this
Button b = new Button();
b.Text = e.KeyChar.ToString();
if (panel1.Enabled)
{
if (e.KeyCode == Keys.Return)
btnequal_Click(null, null);
if (e.KeyChar >= '0' && e.KeyChar <= '9')
{
Numbers(b, null);
foreach (Button c in panel1.Controls)
{
if (c.Text == b.Text)
{
c.Focus();
}
}
}
else
if (e.KeyChar == '+' || e.KeyChar == '-' || e.KeyChar == '/' || e.KeyChar == '*')
{
Operations(b, null);
foreach (Button c in panel1.Controls)
{
if (c.Text == b.Text)
{
c.Focus();
}
}
}
else
if (e.KeyChar == '.')
{
btndot_Click(null, null);
btndot.Focus();
}
else
if (e.KeyChar == '\b')
{
btnbackspace_Click(b, null);
btnbackspace.Focus();
}
}
Ravi RajPosted Nov 3, 2013, 1:57 PM
I haven't get your problem, but after reading the code I will suggest one thing that try to use Keys.Enter instead of Keys.Return.
Moreover, If you will detail your problem, it will be more easier to give you appropriate answer like what error or output you are getting etc.
FroglegPosted Nov 3, 2013, 1:01 PM
1: Enter first numbers into textbox
2: Select mode ie addition, subtraction etc and clear textbox
storing value as decimal
3: Enter second numbers into textbox
4: Press enter and according to mode, after changing second
value to decimal and calculating answer- display in textbox
//create mode
enum sumType
{
add,
subtract,
multiply,
divide
}
sumType whichSumType;
//to set
whichSumType = sumType.add;
//to use
if(e.KeyCode == Keys.Return)
{
If (whichSumType == sumType.add)
{
//c=a+b;
}
else if(whichSumType == sumType.multiply)
{
//c=a*b;
}
}