In this example, we’ll learn How to calculate area and perimeter of a rectangle in C# WinForm. To find the area of a rectangle or a square you need to multiply the length and the width of a rectangle.
Form Design:
Source Code:
1 2 3 4 5 6 7 8 9 10 11 | private void button1_Click(object sender, EventArgs e) { int width = Convert.ToInt32(txtWidth.Text); int length = Convert.ToInt32(txtLength.Text); int area = width * length; int perimeter = (width + length) * 2; lblPerimeter.Text = "Perimeter : " + perimeter; lblArea.Text = "Area : " + area; } |
Output: