37
Programming in C# Programming in C# Project 1: Project 1: Set the text in the Form’s title bar. Change the Form’s background color. Place a Label control on the Form. Display text in a Label control. Place a PictureBox control on the Form. Display an image in a PictureBox control. Run an application.

Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Programming in C#Programming in C#

●● Project 1:Project 1:Set the text in the Form’s title bar.Change the Form’s background color.Place a Label control on the Form.Display text in a Label control.Place a PictureBox control on the Form.

Display an image in a PictureBox control.Run an application.

Page 2: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

TestTest--Driving the Driving the WelcomeWelcomeApplicationApplication

Welcome application running.Close box

Page 3: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Welcome ApplicationConstructing the Welcome Application

● Changing the Form’s file nameLocate the Solution ExplorerSelect the fileChange the File Name property

Page 4: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Blank Form.

Toolbar

Form title bar

Form file name

IDE title bar Solution Explorer window

Solution name

Project name

Blank Form

Page 5: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Changing the Form’s file name.

File properties

New file name

New property value

Selected property description

Selected property

Page 6: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Changing the Form’s title displayLocate Solution ExplorerSelect the Text propertyChange the text

Setting the Form’s Text property.

Selected property description

Selected property Property value

Page 7: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Title bar changes to display Form’s Text property

Title bar for the Welcome application.

Title bar

Page 8: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Form with sizing handles.

Grid

Height

Disabled sizing handle

Mouse pointer over an enabled sizing handle

Enabled sizing handle

Width

Page 9: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Resizing the Form

Expand the Size propertyChange the WidthChange the Height

Size property values for the Form.

Size property values

Page 10: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Changing the Form’s background colorLocate the BackColor property

System tab (default)Web tabCustom tab

Page 11: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Viewing the Custom palette in the Form’s BackColor property value field.

Tabs

Custom colors can be added to the white boxes

Custom palette

Down-arrow ButtonCurrent color

Page 12: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Custom tab paletteDefine Color dialog

Create your own colorsRGB values

Page 13: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Adding a color to the Custom palette.

Blue component (169)

Green component (237)

Color preview Red component (255)

Adds a color to Custom palette

Page 14: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● ToolboxWindows Forms tab

Clicking the Windows Forms tab in the Toolbox.

Windows Forms tab

Label control

Page 15: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Label added to Form

Adding a Label to the Form.

New background color

Sizing handle (enabled)Label control

Page 16: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Adding text to the Label

Label’s content changes to reflect new Text value

Label after updating its Text property.

Updated Text property value too large for Label

Page 17: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Resizing the Label

Text re-aligns to fit new Label size

Label after it has been resized.

Label resized vertically and horizontally

Page 18: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Moving the Label on the Form

Centered Label.

Centered Label

Page 19: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Changing the fontLocate Solution ExplorerSelect the Label

Select Font property

Properties window displaying the Label’s properties.

Ellipsis Button

Page 20: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Font dialogChange text by changing values in dialogs

Page 21: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Font dialog for selecting fonts, styles and sizes.

Current font

Font dialog

Font sample

Page 22: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Text alignmentAccess TextAlign propertySelect appropriate option

Page 23: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Centering the Label’s text.

Top-center alignment option

Text alignment options

Page 24: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Inserting a pictureSelect the PictureBox control

Drop control onto Form

Page 25: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Inserting and aligning the PictureBox.

Updated Label

PictureBox

Page 26: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Changing PictureBox propertiesLocate Solution ExplorerLocate Image property

Image property of the PictureBox.

Image property value (no image selected)

Ellipsis Button

Image preview box (no image currently displayed)

Page 27: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Selecting the pictureNavigate the Open dialog to the picture locationClick Open

Page 28: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

Open dialog used to browse for a PictureBox image.

bug.png file (may display bugdepending on your settings)

Page 29: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Resizing the imageChange property SizeMode

StretchImage scales image in PictureBox

Change property Size

Newly inserted image.

PictureBox too small for image

Page 30: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Previewed image in Image property

Image previewed in the Image property value field.

Previewed image

Page 31: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Align the imageFormat > Center in Form > Horizontally

Page 32: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

PictureBox displaying an image.

Newly inserted image

Page 33: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Locking the controlsDisallow accidental resizing and relocation of controls

Locking controls by using the Format menu.

Lock Controls option

Page 34: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

● Running the applicationTitle bar indicates the current application modeDebug > Start

● Closing the running applicationClick the application’s close box

Page 35: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Constructing the Constructing the WelcomeWelcome ApplicationApplication

IDE in run mode, with the application running in the foreground.

IDE title bar displaying [run]

Form (with grid)

Running application

Page 36: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Objects used in the Objects used in the WelcomeWelcomeApplicationApplication

● ComboBox

Located at top of Properties windowDisplays the names and class types of Form and control objects

Component object box expanded to show the Welcome application’s objects.

Welcomeapplication GUI objects

Page 37: Programming in C# - City University of New Yorknatacha/TeachSpring_2013/CSC330/... · 2013-01-28 · Programming in C# Project 1: ¾Set ... ¾Windows Forms tab Clicking the Windows

Objects used in the Objects used in the WelcomeWelcomeApplicationApplication

● NamespacesOrganizes classes by functionality Directory-like entitiesSystem.Windows.Forms

The name and class type of an object are displayed in theProperties window’s component object box.

Name of object (Form1) Namespace (System.Windows.Forms)

Class type of object (Form)