Hey Leute,
ich bin jetzt dabei, einen Taschenrechner zu bauen.
Hier mein XAML:
Alles anzeigen
Und hier mein C#:
Alles anzeigen
Ich möchte, dass ich ohne in die TextBox zu klicken (also per NumPad und wie im Windows-Taschenrechner) Zahlen hineinschreiben kann. Benötige dringend Hilfe. Danke
Euer Kirk
P.S.: Es wäre auch toll, wenn Ihr mir in meinem anderen Thema (ComboBox-Inhalt an DataGrid senden) helft.
ich bin jetzt dabei, einen Taschenrechner zu bauen.
Hier mein XAML:
Quellcode
- <Window x:Class="WpfApplication2.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:Taschenrechner_3"
- mc:Ignorable="d"
- Title="Rechner" Height="350" Width="265" ResizeMode="CanMinimize" KeyDown="Window_KeyDown">
- <Grid>
- <Grid.RowDefinitions>
- <!--Zeilen-->
- <RowDefinition Height="16"/>
- <RowDefinition Height="32" />
- <RowDefinition Height="10" />
- <RowDefinition Height="40" />
- <RowDefinition Height="10" />
- <RowDefinition Height="40"/>
- <RowDefinition Height="10"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="10"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="10"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="10"/>
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="28" />
- <ColumnDefinition Width="40" />
- <ColumnDefinition Width="10"/>
- <ColumnDefinition Width="40" />
- <ColumnDefinition Width="10" />
- <ColumnDefinition Width="40"/>
- <ColumnDefinition Width="10"/>
- <ColumnDefinition Width="40"/>
- <ColumnDefinition Width="20"/>
- </Grid.ColumnDefinitions>
- <Button x:Name="eins" Content="1" FontSize="16" FontWeight="Bold" Grid.Column="1" Grid.Row="3" IsTabStop="False" Focusable="False" Click="eins_click" Cursor="Hand" BorderBrush="Black" KeyDown="eins_KeyDown"/>
- <Button x:Name="zwei" Content="2" FontSize="16" FontWeight="Bold" Grid.Column="3" Grid.Row="3" Click="zwei_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="drei" Content="3" FontSize="16" FontWeight="Bold" Grid.Column="5" Grid.Row="3" Click="drei_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="plus" Content="+" FontSize="16" FontWeight="Bold" Grid.Column="7" Grid.Row="3" Click="plus_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="vier" Content="4" FontSize="16" FontWeight="Bold" Grid.Column="1" Grid.Row="5" Click="vier_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="fünf" Content="5" FontSize="16" FontWeight="Bold" Grid.Column="3" Grid.Row="5" Click="fünf_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="sechs" Content="6" FontSize="16" FontWeight="Bold" Grid.Column="5" Grid.Row="5" Click="sechs_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="minus" Content="-" FontSize="16" FontWeight="Bold" Grid.Column="7" Grid.Row="5" Click="minus_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="sieben" Content="7" FontSize="16" FontWeight="Bold" Grid.Column="1" Grid.Row="7" Click="sieben_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="acht" Content="8" FontSize="16" FontWeight="Bold" Grid.Column="3" Grid.Row="7" Click="acht_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="neun" Content="9" FontSize="16" FontWeight="Bold" Grid.Column="5" Grid.Row="7" Click="neun_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="mal" Content="*" FontSize="16" FontWeight="Bold" Grid.Column="7" Grid.Row="7" Click="mal_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="clean" Content="C" FontSize="16" FontWeight="Bold" Grid.Column="1" Grid.Row="9" Click="clean_Click" IsTabStop="False" Focusable="False" Cursor="Hand" IsCancel="True" BorderBrush="Black"/>
- <Button x:Name="null" Content="0" FontSize="16" FontWeight="Bold" Grid.Column="3" Grid.Row="9" Click="null_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="komma" Content="." FontSize="16" FontWeight="Bold" Grid.Column="5" Grid.Row="9" Click="komma_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="teil" Content="/" FontSize="16" FontWeight="Bold" Grid.Column="7" Grid.Row="9" Click="teil_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <Button x:Name="gleich" Content="=" FontSize="16" FontWeight="Bold" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="11" Cursor="Hand" Click="gleich_Click" IsDefault="True" BorderBrush="Black"/>
- <Button x:Name="lösch" Content="f" FontSize="16" FontWeight="Bold" FontFamily="Wingdings 3" Grid.Column="5" Grid.ColumnSpan="3" Grid.Row="11" Click="lösch_Click" IsTabStop="False" Focusable="False" Cursor="Hand" BorderBrush="Black"/>
- <TextBox x:Name="rechner" BorderBrush="Black" Background="Cyan" FontSize="17" HorizontalContentAlignment="Right" Grid.Column="2" Grid.ColumnSpan="6" Grid.Row="1" TextAlignment="Right" MaxLines="1" FontFamily="Verdana" FontWeight="Bold"/>
- </Grid>
- </Window>
Und hier mein C#:
C-Quellcode
- 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.IO;
- using System.Globalization;
- using System.Deployment;
- using System.Collections;
- 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 WpfApplication2
- {
- /// <summary>
- /// Interaktionslogik für MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void eins_click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "1";
- }
- private void zwei_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "2";
- }
- private void drei_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "3";
- }
- private void plus_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "+";
- }
- private void vier_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "4";
- }
- private void fünf_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "5";
- }
- private void sechs_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "6";
- }
- private void minus_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "-";
- }
- private void sieben_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "7";
- }
- private void acht_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "8";
- }
- private void neun_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "9";
- }
- private void mal_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "*";
- }
- private void clean_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text = "";
- }
- private void null_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "0";
- }
- private void komma_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += ",";
- }
- private void teil_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "/";
- }
- private void lösch_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text = rechner.Text.Remove(rechner.Text.Length - 1, 1);
- }
- private void gleich_Click(object sender, RoutedEventArgs e)
- {
- rechner.Text += "Text1";
- }
- private void Window_KeyDown(object sender, KeyEventArgs e)
- {
- rechner.Text += e.Key.ToString(rechner.Text = "Text2");
- }
- private void eins_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.NumPad1)
- {
- rechner.Text = "Text3";
- }
- }
- }
- }
Euer Kirk
P.S.: Es wäre auch toll, wenn Ihr mir in meinem anderen Thema (ComboBox-Inhalt an DataGrid senden) helft.




Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Kirk1701A ()