Group Box를 통해 성적입력 과 결과 박스 생성.
코드 (MainWindow.xmal.cs)
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 WpfApp6
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void cal_bt(object sender, RoutedEventArgs e)
{
//string -> int
// total
// korean, english, math, total_bx, avg_bx 모두 text box 이름.
int total = Convert.ToInt32(korean.Text)+ Convert.ToInt32(english.Text)+ Convert.ToInt32(math.Text);
int -> string
string total2 = Convert.ToString(total);
total_bx.Text = total2;
//avegrage
int average = total / 3;
string average2 = Convert.ToString(average);
avg_bx.Text = average2;
}
}
}
소스(MainWindow.xmal 소스)
<Window x:Class="WpfApp6.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:WpfApp6"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<GroupBox Header="성적입력" HorizontalAlignment="Left" Height="299" VerticalAlignment="Top" Width="309" Margin="72,52,0,0" FontSize="20">
<Label Content="국어" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="24,45,0,0" FontSize="15"/>
</GroupBox>
<Label Content="수학" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="102,197,0,0" FontSize="15"/>
<Label Content="영어" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="102,277,0,0" FontSize="15" />
<TextBox x:Name="korean" HorizontalAlignment="Left" Height="38" TextWrapping="Wrap" VerticalAlignment="Top" Width="134" Margin="182,117,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox x:Name="english" HorizontalAlignment="Left" Height="38" TextWrapping="Wrap" VerticalAlignment="Top" Width="134" Margin="182,277,0,0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<TextBox x:Name="math" HorizontalAlignment="Left" Height="38" TextWrapping="Wrap" VerticalAlignment="Top" Width="134" Margin="182,197,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<GroupBox Header="결과" HorizontalAlignment="Left" Height="191" VerticalAlignment="Top" Width="308" Margin="443,70,0,0" FontSize="20">
<Label Content="총점" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,29,0,0" FontSize="15"/>
</GroupBox>
<Label Content="평균" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="459,185,0,0" FontSize="15"/>
<TextBox x:Name="total_bx" HorizontalAlignment="Left" Height="38" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" RenderTransformOrigin="5.031,4.913" Margin="561,117,0,0" IsReadOnly="True" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox x:Name="avg_bx" HorizontalAlignment="Left" Height="44" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" RenderTransformOrigin="5.031,4.913" Margin="561,183,0,0" IsReadOnly="True" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Button Content="계산" HorizontalAlignment="Left" VerticalAlignment="Top" Width="129" Margin="622,300,0,0" RenderTransformOrigin="2.391,8.548" Height="51" FontSize="20" Background="#FFF0F0F0" Click="cal_bt"/>
</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 WpfApp6
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void cal_bt(object sender, RoutedEventArgs e)
{
//string -> int
// total
int total = Convert.ToInt32(korean.Text)+ Convert.ToInt32(english.Text)+ Convert.ToInt32(math.Text);
string total2 = Convert.ToString(total);
total_bx.Text = total2;
//avegrage
int average = total / 3;
string average2 = Convert.ToString(average);
avg_bx.Text = average2;
}
}
}
참조
'C#(.Net)' 카테고리의 다른 글
(WPF)콤보박스를 이용한 식당 리스트의 추가, 삭제(C# 200제, p433) (0) | 2021.07.10 |
---|---|
데이터바인딩 (0) | 2021.07.09 |
(WPF) 리스트박스에 항목을 표시하는 세가지 방법 (C#200제, p429) (0) | 2021.07.09 |
WPF) 3.스크롤바로 RGB 컬러조정(초보자를 위한 c# 200제, p426) (0) | 2021.07.09 |
WPF) 1. 로그인창 만들기. (초보자를 위한 c# 200제, p419) (0) | 2021.07.08 |