Docsity

C# Programming Fundamentals: A Practical Guide with Exercises, Essays (university) of Programming Languages

Partial preview of the text

Download C# Programming Fundamentals: A Practical Guide with Exercises and more Essays (university) Programming Languages in PDF only on Docsity!

UNIT1 - Programming

Week [12] – Getting Started with C#

Lesson Learning Outcome

Pass Merit Distinction LO2 Explain the characteristics of procedural, object- oriented and event driven programming, conduct an analysis of a suitable Integrated Development Environment (IDE) P2 Give explanations of what procedural, object-oriented event driven paradigms are; their characteristics and relationship between them. M2 Analyse the common features that a developer has access to in an IDE. D2 Critically evaluate the source code of an application which implements the program paradigms, in terms of the code structure and characteristics.

Start a New Project

▪ Open Visual studio 2017

▪ Click on create More

project templates

▪ Then it will open new

project window

▪ Select Visual C#, then

select Windows Forms

Application and then

give the project with the

location

IDE Components - Toolbox

▪ The Toolbox contains the various elements that can be added to the forms while developing. ▪ Allows you to add controls to a design surface

Float – Window appears on Top of all others and can be

moved anywhere

Docked – Window is fixed to a particular position. This

position can be changed by clicking on Window title and

dragging.

Auto Hide – Window is automatically hidden when clicked

on another Window

To Reset – Select Window Menu → Select Reset Window

Layout

IDE Components – Server Explorer

▪ Developing windows applications involve working with data. ▪ Use this window to open data connections and to log on to servers and explore their databases and system services

IDE Components – Solution Explorer

▪ The solution explorer displays the various files and folders included in our project. ▪ These files can be the C# code files, class files, configuration file, XML files, database files and more.

Exercise 1 – Message Boxes

▪ Design this Form by simply dragging and

dropping a Button

▪ Double click the ClickMe button and type

the following code in the Event Method

private void clickMe_Click(object sender, EventArgs e) { MessageBox.Show("Welcome to HND !", "WELCOME", MessageBoxButtons.OK, MessageBoxIcon.Information); }

Exercise 2 – Check Boxes

▪ Design this Form by simply using Check Boxes, Text Box and a Buttons ▪ Double click the Submit button and type the code given in the next slide

Exercise 3 – List Boxes

Design this Form by using 6 Buttons, a List Box and a Text Box. Code for Add Button listBox1.Items.Add(textBox1.Text); textBox1.Clear(); Code for Insert Button listBox1.Items.Insert(0,textBox1.Text); textBox1.Clear(); Code for Clear Button listBox1.Items.Clear(); Code for Sort Button listBox1.Sorted = true;

Exercise 3 – Continued….

int x = listBox1.Items.IndexOf(textBox1.Text); if (x == - 1) MessageBox.Show("Item Not Found", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); else listBox1.Items.Remove(textBox1.Text); textBox1.Clear(); Implement Remove as follows : Remove – An item is typed in the Text Box, if it is found in the list box it is removed otherwise an error message is displayed using a message box.

Exercise 4 – Calculator

Design this Form by using Buttons, Labels and Text Boxes. The Code for + Button int n1 = int.Parse(textBox1.Text); int n2 = int.Parse(textBox2.Text); int ans = n1 + n2; textBox3.Text = ans.ToString(); Modify the Sign and Implement the other operators too. Change the code to get a precise answer for Division using Float type.

Exercise 5 – Using a Menus

Create a Menu as shown here. For the Exit Menu Application.Exit(); For All the other Menus var f1 = new Form1(); // Create an Object of the form f1.Show(); // Show the form