First, open Visual Studio (or C# Express Edition) and go to "File>New project>Visual C#" and we select Windows Forms Application.
After this step, insert two textbox, one button and two labels in the form, and after that, change the text of them.
Once that you have inserted the elements, create a method named clcpowerexp2(), writing the following code:
private void clcpowerexp2()
{
int numeroaelevar = int.Parse(textBox1.Text); // base
int expnt = 2; // exponent
double outcome = Math.Pow(numeroaelevar, expnt);
textBox1.Text = outcome.ToString(); // result
}
Like you can see in the code, you must assign the numbers at int array because if not, the code will have errors.
Now, write in the event Click of the button the name of the method, in this case clcpowerexp2() and some lines, like this:
private void button1_Click(object sender, EventArgs e)
{
clcpowerexp2();
label1.Text = "Value";
label2.Hide();
textBox2.Hide();
}
Once that you have done the last steps, press Ctrl+F5 to run the application. If you go to the bin subfolder of your project, you can see and execute the executable of this application.
You can download this example:
powers calculator.zip (41.92K)
Number of downloads: 297




Help






