Alex Biddle

Alex Biddle

  • NA
  • 10
  • 5.2k

C# science calculate

Aug 11 2014 9:00 AM
I am creating a science based calculator app (blank app with xaml and c#) with different formulas such as density and force (i have different buttons for each), what i am struggling with, is, when i click on the force formula button to calculate i want the calculate c# code to change to that formula (i.e. mass * acceleration, also, when i click the force button and then change to mass / volume when i click on the density button)
 
I have thought of doing an if statement for each button but am struggling on how to go about this correctly. i.e. (densitybutton_click)
 
 Below is the code, sorry for the messiness and thanks in advance :)
 
 private void CalculateButton_Click(object sender, RoutedEventArgs e) BUTTON WHICH IS CLICKED TO CALCULATE NUMBERS INPUTTED INTO TB's
{
int Density = int.Parse(LeftTextBox.Text) / int.Parse(RightTextBox.Text);
OutputNumber.Text = Density.ToString();

int result = int.Parse(LeftTextBox.Text) * int.Parse(RightTextBox.Text);
OutputNumber.Text = result.ToString();
}

private void DensityButton_Click(object sender, RoutedEventArgs e) //click this beforehand to show density formula
{
LeftLabelSide.Text = "Mass";
LeftLabelSide.FontSize = 21;
RightLabelSide.FontSize = 21;
RightLabelSide.Text = "Volume";
MathsPoint.Text = "/";
OutputUnit.Text = "KG m3";
LeftTextBox.Text = "";
RightTextBox.Text = "";

MathsPoint.Width = 6;
}
 private void formulaButton_Click(object sender, RoutedEventArgs e) //click to show force formula
{
LeftLabelSide.Text = "Mass";
RightLabelSide.Text = "Acceleration";
RightLabelSide.FontSize = 21;
LeftLabelSide.FontSize = 21;
OutputUnit.Text = "KG";
MathsPoint.Text = "*";
MathsPoint.FontSize = 20;
MathsPoint.Width = 120;
MathsPoint.Height = 5;
MathsPoint.IsEnabled = false;
OutputUnit.IsEnabled = false;


}
 

Answers (1)