programming in c# - city university of new yorknatacha/teachspring_2013/csc330/... ·...
TRANSCRIPT
![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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/1.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/2.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/3.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/4.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/5.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/6.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/9.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/11.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/12.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/14.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/15.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/16.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/17.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/18.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/19.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/20.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/21.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/22.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/23.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/24.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/25.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/26.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/27.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/28.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/29.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/30.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/31.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/32.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/33.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/34.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/35.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/36.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022060418/5f157558c35f5573cb60a42c/html5/thumbnails/37.jpg)
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)