GUI
<Window x:Class="H001_calculator.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:H001_calculator"
mc:Ignorable="d"
Title="사칙계산기" Height="350" Width="350"
Background="Orange">
<Grid>
<Label FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="45,44,187,189">
숫자1
</Label>
<Label FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="45,104,187,131">
숫자2
</Label>
<TextBox x:Name="txtNo1"
Width="100"
Height="30"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="140,44,53.6,186.4">
</TextBox>
<TextBox x:Name="txtNo2"
Width="100"
Height="30"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="140,104,53.6,136.4" RenderTransformOrigin="1.226,0.62">
</TextBox>
<Button x:Name="btnPlus"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="50"
Height="50" Margin="10,155,233.6,65.4"
Click="btnPlus_Click">
+
</Button>
<Button x:Name="btnMinus"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="50"
Height="50" Margin="80,155,163.6,65.4"
Click="btnMinus_Click">
-
</Button>
<Button x:Name="btnTimes"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="50"
Height="50" Margin="157,155,86.6,65.4"
Click="btnTimes_Click">
*
</Button>
<Button x:Name="btnDivide"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="50"
Height="50" Margin="234,155,9.6,65.4"
Click="btnDivide_Click">
/
</Button>
<TextBlock x:Name="lblResult"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="31,220,212.6,15.4" RenderTransformOrigin="1.492,0.375">
</TextBlock>
<TextBox x:Name="txtResult"
Width="160"
Height="30"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="96,225,37.6,15.4">
</TextBox>
</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 H001_calculator
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnPlus_Click(object sender, RoutedEventArgs e)
{
double x1 = double.Parse(txtNo1.Text);
double x2 = double.Parse(txtNo2.Text);
double sum = x1 + x2;
lblResult.Text = string.Format("(+) 결과 ");
txtResult.Text = string.Format("{0:F2}",sum);
}
private void btnMinus_Click(object sender, RoutedEventArgs e)
{
double x1 = double.Parse(txtNo1.Text);
double x2 = double.Parse(txtNo2.Text);
double sum = x1 - x2;
lblResult.Text = string.Format("(-) 결과 ");
txtResult.Text = string.Format("{0:F2}", sum);
}
private void btnTimes_Click(object sender, RoutedEventArgs e)
{
double x1 = double.Parse(txtNo1.Text);
double x2 = double.Parse(txtNo2.Text);
double sum = x1 * x2;
lblResult.Text = string.Format("(*) 결과 ");
txtResult.Text = string.Format("{0:F2}", sum);
}
private void btnDivide_Click(object sender, RoutedEventArgs e)
{
double x1 = double.Parse(txtNo1.Text);
double x2 = double.Parse(txtNo2.Text);
double sum = x1 / x2;
lblResult.Text = string.Format("(/) 결과 ");
txtResult.Text = string.Format("{0:F2}", sum);
}
}
}
'C# > Basics' 카테고리의 다른 글
Class. 클래스의 멤버 필드와 상수 (0) | 2021.04.25 |
---|---|
Class. 구조체와 클래스 (0) | 2021.04.25 |
F004. ScoreCalc (0) | 2021.04.14 |
W003. BMI계산기 (0) | 2021.04.14 |
F002. Login (0) | 2021.04.14 |