0% found this document useful (0 votes)
13 views4 pages

CS411 Sol Assigenment 2

Uploaded by

Tahir Naeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

CS411 Sol Assigenment 2

Uploaded by

Tahir Naeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Muhammad Tahir Naeem

VU ID: BC210209993

CS411 – Visual Programming

Solution Assignment No. 02

Add Button Click Screenshot:

Multiply Button Click Screenshot:


XML Code:
<Window x:Class="BC210209993.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:BC210209993"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Background="#B3CCB1">
<Grid Margin="0,0,0,-59">
<TextBlock Text="VU ID: BC210209993" HorizontalAlignment="Center"
VerticalAlignment="Top" FontSize="25" Margin="0,20,0,0" Background="#E4A431"
Foreground="Black" Padding="5" Width="750" Height="45" TextAlignment="Center" />

<Label Content="Enter First Number" FontSize="18" FontWeight="Bold"


HorizontalAlignment="Left" VerticalAlignment="Top" Margin="50,85,0,0" Height="35"/>
<TextBox x:Name="txtNumber1" HorizontalAlignment="Center" VerticalAlignment="Top"
Width="200" Height="30" Margin="0,90,0,0"/>

<Label Content="Enter Second Number" FontSize="18" FontWeight="Bold"


HorizontalAlignment="Left" VerticalAlignment="Top" Margin="50,120,0,0" Height="35"/>
<TextBox x:Name="txtNumber2" HorizontalAlignment="Center" VerticalAlignment="Top"
Width="200" Height="30" Margin="0,130,0,0"/>

<Button x:Name="Add" Content="Add" HorizontalAlignment="Left"


VerticalAlignment="Top" Width="150" Background="White" Padding="10"
Margin="200,180,0,0" Click="Add_Click"/>
<Button x:Name="Multiply" Content="Multiply" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="150" Background="White" Padding="10"
Margin="360,180,0,0" Click="Multiply_Click"/>
<Button x:Name="Clear" Content="Clear" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="150" Background="White" Padding="10"
Margin="520,180,0,0" Click="Clear_Click"/>

<Label Content="Result:" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"


VerticalAlignment="Top" Margin="50,300,0,0" Height="35" />
<TextBox x:Name="resultBox" HorizontalAlignment="Center" VerticalAlignment="Top"
Width="600" Height="30" Background="#ECD3D3" Margin="70,300,0,0" IsReadOnly="True" />

</Grid>
</Window>

XLM CS Code:
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 BC210209993
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Add_Click(object sender, RoutedEventArgs e)


{
try
{
int num1 = int.Parse(txtNumber1.Text);
int num2 = int.Parse(txtNumber2.Text);
int result = num1 + num2;
resultBox.Text = result.ToString();
}
catch (FormatException)
{
MessageBox.Show("Please Enter Valid Integer.", "Input Error", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}

private void Multiply_Click(object sender, RoutedEventArgs e)


{
try
{
int num1 = int.Parse(txtNumber1.Text);
int num2 = int.Parse(txtNumber2.Text);
int result = num1 * num2;
resultBox.Text = result.ToString();
}
catch (FormatException)
{
MessageBox.Show("Please Enter Valid Integer.", "Input Error", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}

private void Clear_Click(object sender, RoutedEventArgs e)


{
txtNumber1.Clear();
txtNumber2.Clear();
resultBox.Clear();
}
}
}

You might also like