0% found this document useful (0 votes)
10 views7 pages

CS411_100correct_Complete_Code

CS411_100correct_Complete_CodeCS411_100correct_Complete_CodeCS411_100correct_Complete_CodeCS411_100correct_Complete_CodeCS411_100correct_Complete_Code

Uploaded by

ahsan sajjad
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)
10 views7 pages

CS411_100correct_Complete_Code

CS411_100correct_Complete_CodeCS411_100correct_Complete_CodeCS411_100correct_Complete_CodeCS411_100correct_Complete_CodeCS411_100correct_Complete_Code

Uploaded by

ahsan sajjad
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/ 7

Visual Programming (CS411)

Assignment # 02 (GRADED)

100% correct code


you need to use the visual studio to make the Assignment You need to submit three files
mainxaml mainc# and Gif file you need to zip these three files and submit.

You Need to some possible change

Must to change you ID

Xaml code
<Window x:Class="BC12345678.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:BC210403783"
mc:Ignorable="d"
Title="Your Name " Height="450" Width="800">
<Grid Background="Magenta">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Top" Width="800"
Height="40">
<Label Content="VUID: BC12345678" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="792" Height="49" Background="CadetBlue"
Foreground="Brown" FontSize="30" FontWeight="Bold"></Label>
</StackPanel>
<RadioButton x:Name="radioButtonLength" Content="Length" HorizontalAlignment="Left"
Margin="336,86,0,0" VerticalAlignment="Top" Height="23" Width="78"
Checked="RadioButton_Checked" FontSize="16" FontWeight="Bold"/>

<RadioButton x:Name="radioButtonTemp" Content="Temperature"


HorizontalAlignment="Left" Margin="336,114,0,0" VerticalAlignment="Top" Height="23"
Width="105" Checked="RadioButton_Checked" FontSize="16" FontWeight="Bold"/>

<Label x:Name="L1" Content="Length Converter" HorizontalAlignment="Left"


VerticalAlignment="Top" FontSize="20" FontWeight="Bold" Foreground="Blue"
Margin="538,192,0,0" RenderTransformOrigin="0.5,0.5" Width="242">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="43.118"/>
<TranslateTransform/>
</TransformGroup>
</Label.RenderTransform>
</Label>

Ask Any Time 03429311964


<Label x:Name="L2" Content="Enter Value" HorizontalAlignment="Left"
Margin="88,168,0,0" VerticalAlignment="Top" FontSize="16" FontWeight="Bold"></Label>
<TextBox x:Name="inputValue" HorizontalAlignment="Left" Height="31"
Margin="341,168,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"
FontSize="16"></TextBox>

<Label x:Name="L3" Content="Convert To" HorizontalAlignment="Left"


Margin="88,224,0,0" VerticalAlignment="Top" FontSize="16" Width="93"
FontWeight="Bold"></Label>
<ComboBox x:Name="inputType" HorizontalAlignment="Left" Margin="341,222,0,0"
VerticalAlignment="Top" Width="120" Height="33"></ComboBox>

<Button x:Name="btn1" Content="Convert" HorizontalAlignment="Left"


Margin="357,293,0,0" VerticalAlignment="Top" Width="86" FontSize="14"
BorderBrush="{x:Null}" Background="Aquamarine" Height="40" FontWeight="Bold"
Click="Btn1_Click"></Button>

<Button x:Name="btn2" Content="Clear" HorizontalAlignment="Left"


Margin="457,293,0,0" VerticalAlignment="Top" Width="86" FontSize="14"
BorderBrush="{x:Null}" Background="LightCoral" Height="40" FontWeight="Bold"
Click="Btn2_Click"></Button>

<Label x:Name="L4" Content="Result:" HorizontalAlignment="Left" Margin="243,345,0,0"


VerticalAlignment="Top" FontSize="18" Width="93" FontWeight="Bold"
Foreground="Blue"></Label>

<TextBlock x:Name="TB1" HorizontalAlignment="Left" Margin="329,350,0,0"


TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="394" FontSize="18"
FontWeight="Bold" Height="34" Foreground="Yellow" Visibility="Hidden"></TextBlock>

</Grid>
</Window>

C# complete code
using System;

using System.Windows;

namespace BC12345678

public partial class MainWindow : Window

Ask Any Time 03429311964


public MainWindow()

InitializeComponent();

InitializeComboBoxItem();

radioButtonLength.IsChecked = true;

UpdateUIForLength();

private void InitializeComboBoxItem()

inputType.Items.Add("Centimeter");

inputType.Items.Add("Inches");

inputType.Items.Add("Feet");

inputType.Items.Add("Yards");

private void UpdateUIForLength()

L2.Content = "Enter Length in Meters";

L3.Content = "Convert To:";

L1.Content = "Length Converter";

InitializeComboBoxItem();

inputType.SelectedItem = "Centimeter";

Ask Any Time 03429311964


private void UpdateUIForTemperature()

L2.Content = "Enter Temperature in Celsius";

L3.Content = "Convert To:";

L1.Content = "Temperature Converter";

inputType.Items.Clear();

inputType.Items.Add("Fahrenheit");

inputType.Items.Add("Kelvin");

inputType.SelectedItem = "Fahrenheit";

private void RadioButton_Checked(object sender, RoutedEventArgs e)

if (radioButtonLength.IsChecked == true)

UpdateUIForLength();

else

UpdateUIForTemperature();

Ask Any Time 03429311964


private void Btn2_Click(object sender, RoutedEventArgs e)

inputValue.Clear();

TB1.Visibility = Visibility.Hidden;

radioButtonLength.IsChecked = true;

InitializeComboBoxItem();

UpdateUIForLength();

private void Btn1_Click(object sender, RoutedEventArgs s)

double input;

if (double.TryParse(inputValue.Text, out input))

double convertedValue = 0.0;

string result = "";

if (radioButtonLength.IsChecked == true)

string unit = inputType.SelectedItem as string;

switch (unit)

case "Centimeter":

convertedValue = input * 100;

Ask Any Time 03429311964


break;

case "Inches":

convertedValue = input * 39.37;

break;

case "Feet":

convertedValue = input * 3.281;

break;

case "Yards":

convertedValue = input * 1.094;

break;

default:

MessageBox.Show("Please Select the Length", "Information",


MessageBoxButton.OK);

return;

result = $"{input} Meters is Equal To {convertedValue:F2} {unit}";

else

string unit = inputType.SelectedItem as string;

switch (unit)

case "Fahrenheit":

convertedValue = (input * 9 / 5) + 32;

break;

Ask Any Time 03429311964


case "Kelvin":

convertedValue = input + 273.15;

break;

default:

MessageBox.Show("Please Select the Temperature", "Information",


MessageBoxButton.OK);

return;

result = $"{input} Celsius is Equal To {convertedValue:F2} {unit}";

// Update TB1.Text once after the conditional checks

TB1.Text = result;

TB1.Visibility = Visibility.Visible;

else

MessageBox.Show("Please Enter the value", "Information", MessageBoxButton.OK);

Ask Any Time 03429311964

You might also like