GUI
<Window x:Class="W003_BMI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:W003_BMI"
mc:Ignorable="d"
Title="BMI계산기" Height="433.598" Width="391.215"
Background="Aquamarine">
<Grid>
<TextBlock HorizontalAlignment="Left" Width="60" Margin="84,112,0,0" TextWrapping="Wrap" Text="키(cm)" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Width="60" Margin="84,159,0,0" TextWrapping="Wrap" Text="체중(kg)" VerticalAlignment="Top"/>
<TextBox x:Name="txtHeight" HorizontalAlignment="Left" Height="23" Margin="173,111,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" HorizontalContentAlignment="Center" Text=""/>
<TextBox x:Name="txtWeight" HorizontalAlignment="Left" Height="23" Margin="173,158,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" HorizontalContentAlignment="Center" Text=""/>
<Button x:Name="btnBMI" Content="BMI 계산" HorizontalAlignment="Left" Margin="108,209,0,0" VerticalAlignment="Top" Width="158" Height="29" Click="btnBMI_Click"/>
<TextBlock x:Name="lblResult" HorizontalAlignment="Left" Margin="81,278,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="34" Width="212"/>
</Grid>
</Window>
코드
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace W003_BMI
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window //from을 상속받는 from1
{
public MainWindow()
{
InitializeComponent();
}
private void btnBMI_Click(object sender, RoutedEventArgs e)
{
if (txtHeight.Text == "" || txtWeight.Text == "")
{
lblResult.Text = "키와 체중을 입력하세요";
return;
}
double h = double.Parse(txtHeight.Text) / 100;
double w = double.Parse(txtWeight.Text);
double bmi = w / (h * h);
//lblResult.Text = "당신의 BMI는 " + bmi + " 입니다.";
lblResult.Text = string.Format("당신의 BMI는 {0:F2}입니다.", bmi); //F2 = 소숫점 둘쨰 자리 까지
//F1 키 도움말
}
}
}
'C# > Basics' 카테고리의 다른 글
H001. 사칙연산 계산기 만들기 (0) | 2021.04.25 |
---|---|
F004. ScoreCalc (0) | 2021.04.14 |
F002. Login (0) | 2021.04.14 |
F001. Hello (0) | 2021.04.14 |
C#으로 bmi 계산기 만들기 (0) | 2021.03.07 |