0% found this document useful (0 votes)
135 views

Comp 121 Computer Programming II: Laboratory Manual in

The document is a laboratory manual for a C# programming course. It contains 4 sections that outline programming assignments for students to complete, including creating a simple registration form, calculator, ordering system, and floating button design. Each section provides code examples and explanations of the tasks for students to implement the programming concepts and skills taught in the course.

Uploaded by

Rodjean Simballa
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)
135 views

Comp 121 Computer Programming II: Laboratory Manual in

The document is a laboratory manual for a C# programming course. It contains 4 sections that outline programming assignments for students to complete, including creating a simple registration form, calculator, ordering system, and floating button design. Each section provides code examples and explanations of the tasks for students to implement the programming concepts and skills taught in the course.

Uploaded by

Rodjean Simballa
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/ 15

C# Programming 1

Laboratory Manual in
Comp 121
Computer Programming II
Second Semester, School Year 2019-2020

Part 1: Basic C# Programming

SIMBALLA, RODJEAN A,
College of Computer Studies
Eastern Samar State University

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 2

LABORATORY NO. 1
SIMPLE REGISTRATION FORM
namespace Laboratory_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listCity_SelectedIndexChanged(object sender, EventArgs e)
{
string text = listCity.GetItemText(listCity.SelectedItem);
MessageBox.Show(text);
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void chkjava_CheckedChanged(object sender, EventArgs e)
{
MessageBox.Show("Java");
}
private void chkCplusplus_CheckedChanged(object sender, EventArgs e)
{
MessageBox.Show("C++");
}
private void chkSharp_CheckedChanged(object sender, EventArgs e)
{
MessageBox.Show("C#");
}
private void chkvisualbasic_CheckedChanged(object sender, EventArgs e)
{
MessageBox.Show("VISUAL BASIC");
}
private void button1_Click(object sender, EventArgs e)
{
String username = txtUserName.Text;
String password = textPass.Text;
MessageBox.Show("Welcome " + (username + password));

Form2 f = new Form2();


f.Show();
this.Hide();
}
}
}

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 3

OUTPUT:

LABORATORY NO. 2
SIMPLE CALCULATOR
namespace
{
public partial class Form1 : Form
{
Double resultValue = 0;
String operationPerformed = "";
bool isoperationPerformed = false;
public Form1()
{
InitializeComponent();
}
{
if ((textBox_Result.Text == "0") || (isoperationPerformed))
textBox_Result.Clear();
isoperationPerformed = false;
Button button = (Button)sender;
if (button.Text == ".")
{
if (!textBox_Result.Text.Contains("."))
textBox_Result.Text = textBox_Result.Text + button.Text;
}
else
textBox_Result.Text = textBox_Result.Text = button.Text;
}
{
Button button = (Button)sender;

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 4

if (resultValue != 0)
{
button15.PerformClick();
operationPerformed = button.Text;
label_CurrentOperation.Text = resultValue + " " + operationPerformed;
isoperationPerformed = true;
}
else
{
operationPerformed = button.Text;
resultValue = Double.Parse(textBox_Result.Text);
label_CurrentOperation.Text = resultValue + " " + operationPerformed;
isoperationPerformed = true;
}
}
{
textBox_Result.Text = "0";
}
{
textBox_Result.Text = "0";
resultValue = 0;
}
{
switch (operationPerformed)
{
case "+":
textBox_Result.Text = (resultValue +
Double.Parse(textBox_Result.Text)).ToString();
break;
case "-":
textBox_Result.Text = (resultValue -
Double.Parse(textBox_Result.Text)).ToString();
break;
case "*":
textBox_Result.Text = (resultValue *
Double.Parse(textBox_Result.Text)).ToString();
break;
case "/":
textBox_Result.Text = (resultValue /
Double.Parse(textBox_Result.Text)).ToString();
break;
default:
break;

}
resultValue = Double.Parse(textBox_Result.Text);
label_CurrentOperation.Text = "";

}
}
}

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 5

OUTPUT:

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 6

LABORATORY NO. 3
SIMPLE ORDERING SYSTEM
namespace orderingRodjean
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add("KISSES");
listBox2.Items.Add("255.00");
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add("MARS");
listBox2.Items.Add("250.00");
}
private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Add("HERSHEYS");
listBox2.Items.Add("260.00");
}
private void button4_Click(object sender, EventArgs e)
{
listBox1.Items.Add("DAIRYMILK");
listBox2.Items.Add("135.00");
}
private void button5_Click(object sender, EventArgs e)
{
listBox1.Items.Add("ALMONDS");
listBox2.Items.Add("500.00");
}
private void button6_Click(object sender, EventArgs e)
{
listBox1.Items.Add("COCOBALLS");
listBox2.Items.Add("280.00");
}
private void button8_Click(object sender, EventArgs e)
{
decimal sum = 0;
for (int i = 0; i < listBox2.Items.Count; i++)
{
sum += Convert.ToDecimal(listBox2.Items[i].ToString());
}
textBox1.Text = Convert.ToString(sum);
}
private void button9_Click(object sender, EventArgs e)
{

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 7

int index1, index2;


index1 = listBox1.SelectedIndex;
index2 = listBox2.SelectedIndex;
if (index1 >= 0)
{
listBox1.Items.RemoveAt(index1);
listBox2.Items.RemoveAt(index2);
}
}
private void button11_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
listBox2.Items.Clear();
textBox1.Text = "";
}
private void button7_Click(object sender, EventArgs e)
{
listBox3.Items.AddRange(listBox1.Items);
listBox3.Items.Add("TOTAL AMOUNT");
listBox4.Items.AddRange(listBox2.Items);
listBox4.Items.Add(textBox1.Text);
listBox3.Items.Add("-------------------------------------");
listBox3.Items.Add("-------------------------------------");
listBox4.Items.Add("-------------------------------------");
listBox4.Items.Add("-------------------------------------");

listBox1.Items.Clear();
listBox2.Items.Clear();
textBox1.Text = "";
}
private void button12_Click(object sender, EventArgs e)
{
listBox3.Items.AddRange(listBox1.Items);
listBox3.Items.Add("TOTAL AMOUNT");
listBox4.Items.AddRange(listBox2.Items);
listBox4.Items.Add(listBox2.Items);
listBox3.Items.Add("------------------------------------------------");
listBox3.Items.Add("------------------------------------------------");
listBox4.Items.Add("------------------------------------------------");
listBox3.Items.Add("------------------------------------------------");

listBox1.Items.Clear();
listBox4.Items.Clear();
MessageBox.Show("YUMMY CHOCOLATES BITCH");
}
private void pictureBox3_Click(object sender, EventArgs e)
{
}
private void pictureBox4_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 8

OUTPUT:

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 9

LABORATORY NO. 4
SIMPLE FLOT DESIGN
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BTN_MOVE(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.BackColor = Color.LawnGreen;
}
private void btn_Leave(object sender, EventArgs e)
{
Button button = (Button)sender;
button.BackColor = Color.Transparent;
}
private void button5_Click(object sender, EventArgs e)
{
shopping1.BringToFront();
}
private void button6_Click(object sender, EventArgs e)
{
calendar1.BringToFront();
}
private void button7_Click(object sender, EventArgs e)
{
network1.BringToFront();
}
private void button8_Click(object sender, EventArgs e)
{
ecology1.BringToFront();
}
private void button9_Click(object sender, EventArgs e)

{
statistic1.BringToFront();
}
}
}
}

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 10

OUTPUT:

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 11

LABORATORY NO: 5
PRELIMINARY EXAMINATION
PERSONAL INFORMATION
FORM 1 CODE:
namespace activty
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
string username;
string password;
username = Convert.ToString(textBox1.Text);
password = Convert.ToString(textBox2.Text);
if ((textBox1.Text == "RODJEANSIMBALLA") && (textBox2.Text == "THEFUCK"))
{
MessageBox.Show("WELCOME BITCH " + (username));
Form2 a = new Form2();
a.Show();
this.Hide();

}
else
{
MessageBox.Show("INCORRECT USERNAME OR PASSWORD");

}
}
}
}

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 12

FORM 1 OUTPUT:

FORM 2 CODE:
namespace activty
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void groupBox1_Enter(object sender, EventArgs e)


{

private void bT_3_Click(object sender, EventArgs e)


{
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
comboBox1.Enabled = false;
radioButton1.Enabled = false;
radioButton2.Enabled = false;
dateTimePicker1.Enabled = false;
numericUpDown1.Enabled = false;
textBox4.Enabled = false;

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 13

textBox5.Enabled = false;
textBox6.Enabled = false;
pictureBox1.Enabled = false;
}

private void numericUpDown1_ValueChanged(object sender, EventArgs e)


{
}
private void bt_1_Click(object sender, EventArgs e)
{
string imageLocation = "";
try
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "jpg files(*.jpg)|*.jpg| PNG file(*.png)|*.png| All
files(*.*)|*.*";

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) ;
{

imageLocation = dialog.FileName;

pictureBox1.ImageLocation = imageLocation;
}
}
catch (Exception)
{
MessageBox.Show("An Error Occured", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void bt_2_Click(object sender, EventArgs e)
{
textBox1.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
comboBox1.Enabled = true;
radioButton1.Enabled = true;
radioButton2.Enabled = true;
dateTimePicker1.Enabled =true;
numericUpDown1.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
pictureBox1.Enabled = true;
}
private void bt_4_Click(object sender, EventArgs e)
{
PrintDialog a = new PrintDialog();
a.ShowDialog();
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = "RODJEANr";
textBox2.Text = "ACAYEN";
textBox3.Text = "SIMBALLA";
comboBox1.Text = "Brgy. 4 TAFT EASTERN SAMAR";
radioButton1.Checked = true;

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 14

numericUpDown1.Value = 18;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox4.Text == "First Year")
{
textBox5.Text = "Samar Eastern Samar";
textBox4.Text = "2012";
textBox6.Text = "2013";
}
else if (textBox4.Text == "Second Year")
{
textBox5.Text = "Taft Eastern Samar";
textBox4.Text = "2013";
textBox6.Text = "2014";
} else if (textBox4.Text == "Third Year")
{
textBox5.Text = "Taft Eastern Samar";
textBox4.Text = "2014";
textBox6.Text = "2014";
textBox6.Text = "2016";

}
else if (textBox4.Text == "Fourth Year")
{
textBox5.Text = "Taft Eastern Samar";
textBox4.Text = "2015";
textBox6.Text = "2017";
}
else
{
MessageBox.Show("Invalid Keyword");
}
}
}
}
FORM2 OUTPUT:

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018
C# Programming 15

Submitted to:
IVY O. BACOLONGAN
INSTRUCTOR, CCS

ESSU-ACAD-708 | Version 2
Effectivity Date: October 5, 2018

You might also like