COMP 106 - PowerPoint PPT Presentation

Comp 106
Download
1 / 27

COMP 106. Review- C# IDE The IDE Form Steps in making a program in C# The Compute Salary Program. Object-Orientation Object Class Properties and Methods C # classes in Microsoft .NET framework. COMP 106. Introductory Graphics First Drawing program Common Methods to draw

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Download Presentation

COMP 106

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Comp 106

COMP 106

  • Review- C# IDE

    • The IDE

    • Form

    • Steps in making a program in C#

    • The Compute Salary Program

  • Object-Orientation

    • Object

    • Class

    • Properties and Methods

    • C # classes in Microsoft .NET framework


Comp 1061

COMP 106

  • Introductory Graphics

    • First Drawing program

    • Common Methods to draw

    • Assignment 1 (10 marks)


3 basics

Menu bar

IDE

Form

Toolbox

Solution Explorer

Properties


Code window

Code window


Program run

Program run…


3 basics

A misspelled word in your code/instructions will cause

the compiler to

display an error message


3 basics

When semi-colon is removed, the compiler says “ ; expected”


What is an object

What is an object

  • an entity which has properties/variables/fields

  • an entity which has methods- an action to be done by the object

properties

make

size

color

date_manufactured

date_shipped

methods

boot

repair

shutdown

connect_to_net

print

A Dell computer


What is a class

What is a class

  • A class – set of objects that share the same properties and methods

HP

Dell

Compaq

class computer


Pop quiz

Pop quiz… 

  • Give me a class name of the following objects

Angelina

Bradd

Catherine

.5 bonus point to be added to your midterm test


Pop quiz1

Pop quiz… 

Give me some properties for the class Actor

class celebrity

methods

properties

screen_name

real_name

dateofbirth

gross_income

hire

sign_contract

act

takeholiday

resign


3 basics

className objectName = new className

  • To create an object from a class,

  • An object is an instance of a class

Example

Computer Dell = new Computer;

Pen pen = new Pen(Color.Black);

How would you create objects Angelina? Bradd? Catherine?

Celebrity Angeline=new Celebrity;

Celebrity Bradd=new Celebrity;

Celebrity Catherine=new Celebrity;


3 basics

  • In C#, the standard format to get the value of the property is:

data = object.propertyname

Example

its_color = Dell.color;

c = pen.Color;


3 basics

  • To set the value of the property,

object.propertyname = data;

Example

Dell.color=red;

pen.color = black;


3 basics

  • To call or invoke the method of the object;

object.methodname(arguments)

Example

Dell.Repair();

Dell.Sell();

Brad.Hire();

Catherine.Resign();


Introductory graphics

Introductory Graphics

  • C# has existing classes : buttons, labels, forms, etc

  • The Microsoft .NET framework has hundreds of classes

  • Programmers can make use of classes to instantiate objects;


Drawing

Drawing..

  • What object do we need?

  • paper

  • pen


Let s draw a rectangle

Let’s draw a rectangle…

paper.DrawRectangle(pen to use, rectangle position, etc)

We “invoke” or “call” the method “DrawRectangle” of object paper.

Arguments or parameters needed to make a rectangle

The method is called by placing a dot “.” between the object name and the method


Actual code to draw a rectangle

Actual code to draw a rectangle..

  • Draw a button, a picturebox inthe form

  • Double click the button

  • Enter the following code

{

Graphics paper ;

paper = pictureBox1.CreateGraphics();

Pen pen = new Pen(Color.Black);

paper.DrawRectangle(pen, 10,10,100,50);

paper.DrawRectangle(pen, 10,75,100,100);

}


Pixel coordinate in c

Pixel coordinate in C#

horizontal

form

picture

box

0,0

vertical

100

0,0

200

shape in picture box


3 basics

Output after running the program…

paper.DrawRectangle(pen, 10,10,100,50);

paper.DrawRectangle(pen, 10,75,100,100);


C provides facilities to draw shapes

C# provides facilities to draw shapes:

  • lines

  • ellipses (i.e. ovals,circles)

  • filled rectangles and ellipses;

  • images from files.

You can change the color of the pens and use brushes of a chosen color to fill shapes


Methods for drawing shapes lines etc

Methods for drawing shapes, lines, etc

  • DrawRectangle

    • a pen object;

    • the horizontal value of the top edge corner of the rectangle

    • the vertical value of the top left corner of the rectangle

    • the width of the rectangle

    • the height of the rectangle

  • DrawLine

    • a pen object;

    • the horizontal value of the start of the line

    • the vertical value of the start of the line

    • the horizontal value of the end of the line

    • the vertical value of the end of the line

      paper.Drawline(pen, 0,0,10,10);


3 basics

  • DrawEllipse –imagine the ellipse as an oval squeezed inside a rectangle

    • a pen object;

    • the horizontal value of the top edge corner of the rectangle

    • the vertical value of the top left corner of the rectangle

    • the width of the rectangle

    • the height of the rectangle


3 basics

  • FillRectangle –needs a brush object instead of a pen;

    • A brush object;

    • the horizontal value of the top edge corner of the rectangle

    • the vertical value of the top left corner of the rectangle

    • the width of the rectangle

    • the height of the rectangle

Solidbrush myBrush = new Solidbrush(Color.black);

paper.FillRectangle(myBrush,10,10,90,90);


3 basics

  • DrawImage – use to display a JPG or bitmap file

    • A bitmap object containing an image from a file

    • the horizontal value of the top edge corner of the rectangle

    • the vertical value of the top left corner of the rectangle

    • the width of the rectangle

    • the height of the rectangle

Example code:

Bitmap pic = new Bitmap(@”c:\myphoto.jpg”);

paper.DrawImage(pic,130,10,150,150);


Assignment 1

Assignment 1

Due date : Friday, 18 Jan. email your program to

rtg4@cs.waikato.ac.nz

  • Make a program that will draw the outer view of your flat/house. (put a picture of your own outside the house)

  • Make a program that will draw the “eye-bird’s” (inner) view of your flat/house . Include appliances and furniture only. (shapes does not need to be filled with colors)


  • Login