W003. BMI계산기

2021. 4. 14. 01:29· C#/Basics

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
'C#/Basics' 카테고리의 다른 글
  • H001. 사칙연산 계산기 만들기
  • F004. ScoreCalc
  • F002. Login
  • F001. Hello
페프
페프
페프
FFeFF SPACE
페프
전체
오늘
어제
  • 분류 전체보기
    • C++
      • Foundation
      • Programmers
    • C#
      • Foundation
      • Basics
    • Algorithms
    • SQLD
    • Web
      • JavaScript
    • AI-900
    • ETC

블로그 메뉴

  • About
  • 📗 Github
  • Programming_II
hELLO · Designed By 정상우.v4.2.2
페프
W003. BMI계산기
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.