bil528 – bilgisayar programlama ii introduction 1
TRANSCRIPT
![Page 1: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/1.jpg)
BIL528 – Bilgisayar Programlama II
Introduction
1
![Page 2: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/2.jpg)
Contents
• Information about the course• Visual Studio 2012 Environment• Designing a Simple Visual C# Program
2
![Page 3: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/3.jpg)
Course Information
3
![Page 4: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/4.jpg)
About the courseLecturer: Muzaffer DOĞAN
Office Phone: 6562
E-mail Address: [email protected]
Web Page: http://ceng.anadolu.edu.tr/muzafferd/
Teaching Assistant: ---
Course Web Page: http://ceng.anadolu.edu.tr/Ders.aspx?id=78
Class Hours and Location: 09:00-12:00, TUE on B2
Office Hours: 14:00-17:00, THU
Prerequisites: - C / C++ / Java / C# Programming- Object Oriented Programming
Textbooks: Teach Yourself Visual C# 2008 in 24 Hours, James Foxall, Sams Publishing, 2008.Beginning Microsoft Visual C# 2012, Karli Watson, Christian Nagel et al., Wiley Publishing, 2012.Illustrated C# 2012, Daniel Solis, Apress, 2012.
4
![Page 5: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/5.jpg)
Course ContentsWeek 1 Visual Studio 2012 IDE, Creating a New Project
Week 2 Understanding Objects and Collections, Understanding Events
Week 3 Building Forms: Basics and Advanced Techniques
Week 4 Working with Traditional Controls: Labels, Text Boxes, Buttons Check Boxes, List Boxes, Combo Boxes; Using Advanced Controls: Timers, Tabbed Dialog Boxes, Image Lists, List View, Tree View
Week 5 Menus, Toolbars, Status Bar, Creating and Calling Methods
Week 6 First Midterm
Week 7 Using Constants, Data Types, Variables and Arrays; Arithmetic Operations, String Manipulation, Date/Time Adjustments
Week 8 Making Decisions, Looping
5
![Page 6: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/6.jpg)
Course Contents (continued)Week 9 Debugging, Designing Objects Using Classes
Week 10 Interacting with Users, Working with Graphics
Week 11 Performing File Operations, Working with Text Files and the Registry
Week 12 Second Midterm
Week 13 Working with a Database, Controlling Other Applications Using Automation
Week 14 Deploying Applications
Week 15 Final Exam
6
![Page 7: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/7.jpg)
Grading Plan
• 1st MT: 20%, 2nd MT: 20%, Homework: 20%,Final: 40%.
• Curve will be applied to the grades• If your grade is below 80%, you cannot get the
grade AA, but it is not certain that if you pass 80% then you get AA.
• If your grade is below 35%, you certainly fail, but this does not mean that you’ll get at least DD if you pass 35%.
7
![Page 8: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/8.jpg)
Sample Grading Plan
Grade Letter Grade
≥ 80 AA≥ 75 AB≥ 70 BA≥ 65 BB≥ 60 BC
Grade Letter Grade
≥ 55 CB≥ 50 CC≥ 45 CD≥ 40 DC≥ 35 DD< 35 FF
8
![Page 9: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/9.jpg)
Attendances
• You don’t have to attend the classes but recent experiences show that the students who attend the classes are more successful
• All students are responsible for visiting the website of the course at least two times in each week
• Announcements, assignments, grades, and project subjects will be published on the website.
9
![Page 10: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/10.jpg)
Supplementary Software
• In this course, you’ll need Visual Studio 2010 software
• You can download it from a shared folder as explained in http://ceng.anadolu.edu.tr/msdn.aspx page
• You can login to the website using your Anadolu e-mail account.
• If you have problems in logging in, please inform me.
10
![Page 11: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/11.jpg)
Creating a New Project
11
![Page 12: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/12.jpg)
12
![Page 13: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/13.jpg)
13
![Page 14: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/14.jpg)
14
![Page 15: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/15.jpg)
15
![Page 16: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/16.jpg)
The First Changes
• The Name property is the first property you should change when you add a new object to your project.
• Change the filename of the form from the Solution Explorer too.
• Note: When you change the filename, Visual Studio asks you to change the name of the form.
16
![Page 17: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/17.jpg)
17
![Page 18: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/18.jpg)
Changing the Title of the Form
• Changing the filename and name of the form does not change the title of the form which is displayed at the top-left corner of the window.
• You should change the title of the form using the Text property.
18
![Page 19: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/19.jpg)
19
![Page 20: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/20.jpg)
Giving the Form an Icon
• Giving the Form an Icon– In the Properties windows, change the Icon
property of the form.• Changing the Size of the Form– Change the Width and Height properties of the
form under the Size property.– Both values are represented in pixels.– You can also size a form by dragging its border.
20
![Page 21: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/21.jpg)
Adding Controls to the Form
• Use the Toolbox window.• Some controls in the toolbox
have visible interface, but some not.
• You can make the toolbox visible always by clicking the pushpin picture at the top-right corner.
21
![Page 22: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/22.jpg)
Designing an Interface
1. Design the form’s user interface2. Write the code behind the interface.
• This procedure is generally the best to design a form.
22
![Page 23: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/23.jpg)
Adding a Visible Control to a Form
• Visible controls can be added in two ways:1. By double-clicking the control2. By dragging the control and dropping on the
form.• You can place the controls wherever you
want by dragging them on the form.• Let’s add two buttons and a PictureBox
control to the form…
23
![Page 24: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/24.jpg)
24
Property Value
Name btnSelectPicture
Location 295, 10
Size 85, 23
Text Select Picture
Property Value
Name btnQuit
Location 295, 40
Text Quit
Property Value
Name picShowPicture
BorderStyle FixedSingle
Location 8, 8
Size 282, 275
![Page 25: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/25.jpg)
Adding an Invisible Control to a Form
• Not all controls have physical appearance.• They are not designed for user interactivity.• Examples: OpenFileDialog and SaveFileDialog
controls• You can add them to the control by the same
way as the visible controls.• They are shown below the form at design time
but they are not shown at the runtime.
25
![Page 26: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/26.jpg)
Adding an OpenFileDialog Control
• Add an OpenFileDialog control to the form and change the following properties:
26
Property Value
Name ofdSelectPicture
Filename <make empty>
Filter Windows Bitmaps|*.BMP|JPEG Files|*.JPG
Title Select Picture
![Page 27: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/27.jpg)
27
![Page 28: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/28.jpg)
Executing the Program
• Simply press Ctrl+F5– Runs the program normally
• You can press F5 or click the debug button on the toolbar instead– But this runs the program in debug mode and it is
a bit slower.• Clicking the buttons does not do anything now
because we didn’t write any code for them!
28
![Page 29: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/29.jpg)
Writing the Code Behind an Interface
• Visual C# is an event-driven language, which means that code is executed in response to events.
• These events might come from users, such as a user clicking a button and triggering its Click event, or from Windows itself.
29
![Page 30: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/30.jpg)
Letting a User Browse for a File
• When you double-click a control on a form in Design view, the default event for that control is displayed in a code window.
• The default event for a Button control is its Click event.
• Double-click the Select Picture button now to access its Click event in the code window.
30
![Page 31: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/31.jpg)
31
![Page 32: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/32.jpg)
The Content of the Methodprivate void btnSelectPicture_Click(object sender, EventArgs e){ // Show the open file dialog box. if (ofdSelectPicture.ShowDialog() == DialogResult.OK) { // Load the picture into the picture box. picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName);
// Show the name of the file in the form’s caption. this.Text = "Picture Viewer (" + ofdSelectPicture.FileName + ")"; }}
32
![Page 33: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/33.jpg)
Terminating a Program Using a Code
• Write the following code into the Click event of the Quit button:
// Close the window and exit the applicationthis.Close();
33
![Page 34: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/34.jpg)
34
![Page 35: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/35.jpg)
Execution of the Program
35
![Page 36: BIL528 – Bilgisayar Programlama II Introduction 1](https://reader035.vdocuments.site/reader035/viewer/2022062221/56649e175503460f94b0369d/html5/thumbnails/36.jpg)
Exercises
• Change your Picture Viewer program so that the user can also locate and select GIF files. (Hint: Change the Filter property of the OpenFileDialog control.)
• Change the background color of the form.• Change the background color of the buttons.• Change the color of the texts on the buttons.• What happens if you try to display a larger
image? How can you solve this problem?36