打开vs,文件,新建,项目,Visual
C#,Windows窗体应用程序.
出现一个windows窗体,从工具栏拖一个TextBox.拖一个button
双击button,进入事件.
Button1_Click()
{
string
strValue
=
textBox1.Text.Trim
(
);
double
pi
=
3.14;
double
dblValue;
bool
IsDouble
=
double.TryParse
(
strValue,
out
dblValue
);
if
(
IsDouble
)
{
double
area
=
pi
*
dblValue
*
dblValue;
double
perimeter
=
2
*
pi
*
dblValue;
MessageBox.Show
(
String.Format
(
"圆的面积是{0},
周长是{1}",
area,
perimeter
)
);
}
else
{
MessageBox.Show
(
String.Format
(
"{0}不是浮点型数字",
strValue
)
);
}