SlideShare uma empresa Scribd logo
1 de 40
Microsoft Visual C# 2010
       Fourth Edition



         Chapter 3
 Using GUI Objects and the
     Visual Studio IDE
Objectives
•   Create a Form in the Visual Studio IDE
•   Use the Toolbox to add a Button to a Form
•   Add Labels and TextBoxes to a Form
•   Name Forms and controls
•   Correct errors
•   Decide which interface to use




Microsoft Visual C# 2010, Fourth Edition         2
Creating a Form in the IDE
• Forms are GUI objects that provide an interface for
  collecting, displaying, and delivering information
• Select New Project after starting Visual Studio
• Then choose Windows Forms Application
• After you click OK in the New Project window, you
  see the IDE main window




Microsoft Visual C# 2010, Fourth Edition                3
Creating a Form in the IDE (cont’d.)




Microsoft Visual C# 2010, Fourth Edition   4
Creating a Form in the IDE (cont’d.)




Microsoft Visual C# 2010, Fourth Edition   5
Creating a Form in the IDE (cont'd.)
• The name of the application shows in three places:
  the title bar, the Solution Explorer, and the
  Properties window
• The main menu lies horizontally across the top
• The Toolbox tab provides a list of controls you can
  drag onto a Form
• The Form Designer appears in the center of the
  screen
• The Solution Explorer allows viewing and
  managing project files and settings
Microsoft Visual C# 2010, Fourth Edition            6
Creating a Form in the IDE (cont'd.)
• The Properties window is for configuring
  properties and events on controls in your user
  interface
• The error list displays messages about compiler
  errors in your code




Microsoft Visual C# 2010, Fourth Edition            7
Creating a Form in the IDE (cont'd.)
• The Program.cs file contains the automatically
  generated Main() method of the application
• Form1.cs contains other automatically generated
  code
     – The code describes what tasks you will assign to the
       controls in your application
• When you create a Windows Form project, Visual
  C# adds a Form to the project and calls it Form1



Microsoft Visual C# 2010, Fourth Edition                  8
Creating a Form in the IDE (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   9
Creating a Form in the IDE (cont'd.)
• In the Properties window, you can change the
  appearance, size, and color of a window
• The Form class contains around 100 properties
• Property names appear in alphabetical order
  (except for Name)




Microsoft Visual C# 2010, Fourth Edition          10
Creating a Form in the IDE (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   11
Using the Toolbox to Add a Button to
               a Form
• When you open the IDE, the left border displays a
  Toolbox tab
     – Open the toolbox, and a list of tool groups is
       displayed
     – The tool groups includes the controls you have seen
       when using a Windows application
• You can drag controls (such as a Button) onto a
  Form
• You can relocate a control by dragging it or delete
  it by selecting it and pressing the Del key

Microsoft Visual C# 2010, Fourth Edition                 12
Using the Toolbox to Add a Button to
           a Form (cont'd.)
• A Button is a clickable object that allows a user to
  interact with a GUI program
• By default, the first button dragged on is named
  button1
     – You should probably change the name to something
       meaningful
• When you click on a control, the Properties window
  shows its properties



Microsoft Visual C# 2010, Fourth Edition              13
Using the Toolbox to Add a Button to
           a Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   14
Using the Toolbox to Add a Button to
           a Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   15
Using the Toolbox to Add a Button to
           a Form (cont'd.)
• Adding functionality to a Button is easy with the
  IDE
     – After dragging the button on to a Form, you double-
       click on it to create a method that executes when the
       user clicks the Button
• You can view the code by selecting View and then
  Code from the main menu




Microsoft Visual C# 2010, Fourth Edition                  16
Using the Toolbox to Add a Button to
           a Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   17
Using the Toolbox to Add a Button to
           a Form (cont'd.)
• You will see many generated statements, some
  confusing
• To make a Button perform an action, you can
  ignore most of these
• Write code between the curly braces of the
  button1_Click() method
• If you change the Name property of the button1
  object, the name of its subsequently created
  Click() method will also change automatically
• You can write anything you want in the Click()
  methods
Microsoft Visual C# 2010, Fourth Edition           18
Adding Labels and TextBoxes to a
               Form
• Labels are controls that you use to display text to
  communicate with an application’s user
• You can drag a Label onto a Form, just like a
  Button
• You can change its Text property to display any
  text you like
     – Depending on the amount of text, you may need to
       resize the label
• In Figure 3-7, “Enter a number” has been assigned
  to label1’s Text property

Microsoft Visual C# 2010, Fourth Edition                  19
Adding Labels and TextBoxes to a
            Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   20
Adding Labels and TextBoxes to a
            Form (cont'd.)
• TextBoxes are controls through which a user can
  enter input data in a GUI application
• If a user is supposed to enter data in a TextBox,
  you frequently want to start with its Text property
  empty
• When a user types a value into a TextBox, it
  becomes the value of the Text property
     – It is a string by default
     – If the user is supposed to enter a number, you’ll
       have to convert it, just as in a console application

Microsoft Visual C# 2010, Fourth Edition                      21
Adding Labels and TextBoxes to a
            Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   22
Adding Labels and TextBoxes to a
            Form (cont'd.)
• The form on the next slide is meant to have the
  user enter two numbers in the TextBoxes
• When the user clicks the Button, the sum of the
  two numbers will be displayed in label3
• You must create the code to do the addition
     – It goes in the button1_Click() method




Microsoft Visual C# 2010, Fourth Edition            23
Adding Labels and TextBoxes to a
            Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   24
Adding Labels and TextBoxes to a
            Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   25
Adding Labels and TextBoxes to a
            Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   26
Adding Labels and TextBoxes to a
            Form (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   27
Naming Forms and Controls
• Provide reasonable Name property values for all
  the controls you place on a Form
     – Conventionally, start control names with a lowercase
       letter and use camel casing
     – Start Form names with an uppercase letter and use
       camel casing
           • A Form is a class, and C# class names conventionally
             start with an uppercase letter
     – Use the type of object in the name
• To rename a control after you have generated code
  for it, use the code refactoring feature
Microsoft Visual C# 2010, Fourth Edition                       28
Naming Forms and Controls (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   29
Naming Forms and Controls (cont'd.)
• When you click Rename, a dialog box opens
     – Type the new method name
• A Preview Changes dialog box will highlight the
  change
     – Confirm the change by clicking Apply




Microsoft Visual C# 2010, Fourth Edition            30
Naming Forms and Controls (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   31
Correcting Errors
• As in console-based programs, you will often
  generate syntax errors
• If you build or run a program with an error, you will
  see “Build failed” in the lower-left corner of the IDE
• You will also see an error dialog box
     – Always click No in response to “Would you like to
       continue and run the last successful build?”
• Errors will be listed in the error list at the lower-left
  corner of the screen
• Double-clicking an error message will take you to
  the location in the code where the error was found
Microsoft Visual C# 2010, Fourth Edition                      32
Correcting Errors (cont'd.)




Microsoft Visual C# 2010, Fourth Edition      33
Correcting Errors (cont'd.)




Microsoft Visual C# 2010, Fourth Edition      34
Correcting Errors (cont'd.)
• When you are working in the Form Designer, it is
  easy to inadvertently double-click a control and
  create an event-handling method you don’t want
     – You can leave the event-handling method empty, but
       that’s considered bad form
     – You cannot just delete the method because, behind
       the scenes, other code will have been created that
       refers to the method
     – Instead, go to the Properties window of the control,
       and then click on its Events button, select the button
       you want to eliminate, and delete the method name
Microsoft Visual C# 2010, Fourth Edition                   35
Correcting Errors (cont'd.)




Microsoft Visual C# 2010, Fourth Edition      36
Deciding Which Interface to Use
• You have learned to create:
     – Console applications
     – GUI applications
• Both types contain basic building blocks
• GUI applications
     – Look “snazzier” and are easy to use
     – GUI applications take longer to develop
• Console applications
     – Simpler; may be better when learning new logical
       constructs
Microsoft Visual C# 2010, Fourth Edition                  37
You Do It
• Working With the Visual Studio IDE
• Providing Functionality for a Button
• Adding a Second Button to a Form




Microsoft Visual C# 2010, Fourth Edition         38
Summary
• Forms are GUI objects that provide an interface for
  collecting, displaying, and delivering information
• The Toolbox displays a list of available controls you
  can add to a Form
     – This list includes Button, CheckBox, and Label
• Labels are controls that you use to display text to
  communicate with an application’s user
• Provide reasonable Name property values for all
  the controls you place on a Form


Microsoft Visual C# 2010, Fourth Edition                39
Summary (cont’d.)
• If you build or run a program that contains a syntax
  error, you see “Build failed” in the lower-left corner
  of the IDE and an error dialog box
• Both console and GUI applications can contain
  variables and constants, decisions, loops, arrays,
  and calls to other methods
     – GUI applications
           • Look “snazzier”
           • Contain controls that a user can manipulate with a
             mouse
           • Usually take longer to develop
Microsoft Visual C# 2010, Fourth Edition                          40

Mais conteúdo relacionado

Mais procurados

Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Warren0989
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02Terry Yoast
 
Computer Programming
Computer ProgrammingComputer Programming
Computer ProgrammingBurhan Fakhar
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 
Operators and Expressions in C#
Operators and Expressions in C#Operators and Expressions in C#
Operators and Expressions in C#Prasanna Kumar SM
 
9781439035665 ppt ch06
9781439035665 ppt ch069781439035665 ppt ch06
9781439035665 ppt ch06Terry Yoast
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06Terry Yoast
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12Terry Yoast
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Testing Model Transformations
Testing Model TransformationsTesting Model Transformations
Testing Model Transformationsmiso_uam
 
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTING
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTINGA WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTING
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTINGJournal For Research
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Nicole Ryan
 

Mais procurados (20)

Chapter 4 5
Chapter 4 5Chapter 4 5
Chapter 4 5
 
Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Chap02
Chap02Chap02
Chap02
 
JavaScript functions
JavaScript functionsJavaScript functions
JavaScript functions
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02
 
Chapter2
Chapter2Chapter2
Chapter2
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Programming in c notes
Programming in c notesProgramming in c notes
Programming in c notes
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Operators and Expressions in C#
Operators and Expressions in C#Operators and Expressions in C#
Operators and Expressions in C#
 
9781439035665 ppt ch06
9781439035665 ppt ch069781439035665 ppt ch06
9781439035665 ppt ch06
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06
 
Intake 38_1
Intake 38_1Intake 38_1
Intake 38_1
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Testing Model Transformations
Testing Model TransformationsTesting Model Transformations
Testing Model Transformations
 
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTING
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTINGA WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTING
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTING
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
 
Visual programming
Visual programmingVisual programming
Visual programming
 

Semelhante a Csc153 chapter 03

hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxEliasPetros
 
LECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxLECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxAOmaAli
 
VB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptVB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptBhuvanaR13
 
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesC# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesSami Mut
 
Membangun Desktop App
Membangun Desktop AppMembangun Desktop App
Membangun Desktop AppFajar Baskoro
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesSami Mut
 
Creating Windows-based Applications Part-I
Creating Windows-based Applications Part-ICreating Windows-based Applications Part-I
Creating Windows-based Applications Part-IUmar Farooq
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesSami Mut
 
Visual Studio 2012 Course Blackboard TIC
Visual Studio 2012 Course Blackboard TICVisual Studio 2012 Course Blackboard TIC
Visual Studio 2012 Course Blackboard TICMauricio Correa
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Designfrancopw
 
Login Project with introduction .pptx
Login Project with introduction .pptxLogin Project with introduction .pptx
Login Project with introduction .pptxkulmiyealiabdille
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lecturesmarwaeng
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0sanket1996
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxAnasYunusa
 

Semelhante a Csc153 chapter 03 (20)

hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
 
LECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxLECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptx
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
 
VB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptVB6_INTRODUCTION.ppt
VB6_INTRODUCTION.ppt
 
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesC# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
 
Membangun Desktop App
Membangun Desktop AppMembangun Desktop App
Membangun Desktop App
 
Ch01
Ch01Ch01
Ch01
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
 
Creating Windows-based Applications Part-I
Creating Windows-based Applications Part-ICreating Windows-based Applications Part-I
Creating Windows-based Applications Part-I
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
 
Visual Studio 2012 Course Blackboard TIC
Visual Studio 2012 Course Blackboard TICVisual Studio 2012 Course Blackboard TIC
Visual Studio 2012 Course Blackboard TIC
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
 
Login Project with introduction .pptx
Login Project with introduction .pptxLogin Project with introduction .pptx
Login Project with introduction .pptx
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptx
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Vb unit t 1.1
Vb unit t 1.1Vb unit t 1.1
Vb unit t 1.1
 
Meaning Of VB
Meaning Of VBMeaning Of VB
Meaning Of VB
 

Último

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Último (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Csc153 chapter 03

  • 1. Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE
  • 2. Objectives • Create a Form in the Visual Studio IDE • Use the Toolbox to add a Button to a Form • Add Labels and TextBoxes to a Form • Name Forms and controls • Correct errors • Decide which interface to use Microsoft Visual C# 2010, Fourth Edition 2
  • 3. Creating a Form in the IDE • Forms are GUI objects that provide an interface for collecting, displaying, and delivering information • Select New Project after starting Visual Studio • Then choose Windows Forms Application • After you click OK in the New Project window, you see the IDE main window Microsoft Visual C# 2010, Fourth Edition 3
  • 4. Creating a Form in the IDE (cont’d.) Microsoft Visual C# 2010, Fourth Edition 4
  • 5. Creating a Form in the IDE (cont’d.) Microsoft Visual C# 2010, Fourth Edition 5
  • 6. Creating a Form in the IDE (cont'd.) • The name of the application shows in three places: the title bar, the Solution Explorer, and the Properties window • The main menu lies horizontally across the top • The Toolbox tab provides a list of controls you can drag onto a Form • The Form Designer appears in the center of the screen • The Solution Explorer allows viewing and managing project files and settings Microsoft Visual C# 2010, Fourth Edition 6
  • 7. Creating a Form in the IDE (cont'd.) • The Properties window is for configuring properties and events on controls in your user interface • The error list displays messages about compiler errors in your code Microsoft Visual C# 2010, Fourth Edition 7
  • 8. Creating a Form in the IDE (cont'd.) • The Program.cs file contains the automatically generated Main() method of the application • Form1.cs contains other automatically generated code – The code describes what tasks you will assign to the controls in your application • When you create a Windows Form project, Visual C# adds a Form to the project and calls it Form1 Microsoft Visual C# 2010, Fourth Edition 8
  • 9. Creating a Form in the IDE (cont'd.) Microsoft Visual C# 2010, Fourth Edition 9
  • 10. Creating a Form in the IDE (cont'd.) • In the Properties window, you can change the appearance, size, and color of a window • The Form class contains around 100 properties • Property names appear in alphabetical order (except for Name) Microsoft Visual C# 2010, Fourth Edition 10
  • 11. Creating a Form in the IDE (cont'd.) Microsoft Visual C# 2010, Fourth Edition 11
  • 12. Using the Toolbox to Add a Button to a Form • When you open the IDE, the left border displays a Toolbox tab – Open the toolbox, and a list of tool groups is displayed – The tool groups includes the controls you have seen when using a Windows application • You can drag controls (such as a Button) onto a Form • You can relocate a control by dragging it or delete it by selecting it and pressing the Del key Microsoft Visual C# 2010, Fourth Edition 12
  • 13. Using the Toolbox to Add a Button to a Form (cont'd.) • A Button is a clickable object that allows a user to interact with a GUI program • By default, the first button dragged on is named button1 – You should probably change the name to something meaningful • When you click on a control, the Properties window shows its properties Microsoft Visual C# 2010, Fourth Edition 13
  • 14. Using the Toolbox to Add a Button to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 14
  • 15. Using the Toolbox to Add a Button to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 15
  • 16. Using the Toolbox to Add a Button to a Form (cont'd.) • Adding functionality to a Button is easy with the IDE – After dragging the button on to a Form, you double- click on it to create a method that executes when the user clicks the Button • You can view the code by selecting View and then Code from the main menu Microsoft Visual C# 2010, Fourth Edition 16
  • 17. Using the Toolbox to Add a Button to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 17
  • 18. Using the Toolbox to Add a Button to a Form (cont'd.) • You will see many generated statements, some confusing • To make a Button perform an action, you can ignore most of these • Write code between the curly braces of the button1_Click() method • If you change the Name property of the button1 object, the name of its subsequently created Click() method will also change automatically • You can write anything you want in the Click() methods Microsoft Visual C# 2010, Fourth Edition 18
  • 19. Adding Labels and TextBoxes to a Form • Labels are controls that you use to display text to communicate with an application’s user • You can drag a Label onto a Form, just like a Button • You can change its Text property to display any text you like – Depending on the amount of text, you may need to resize the label • In Figure 3-7, “Enter a number” has been assigned to label1’s Text property Microsoft Visual C# 2010, Fourth Edition 19
  • 20. Adding Labels and TextBoxes to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 20
  • 21. Adding Labels and TextBoxes to a Form (cont'd.) • TextBoxes are controls through which a user can enter input data in a GUI application • If a user is supposed to enter data in a TextBox, you frequently want to start with its Text property empty • When a user types a value into a TextBox, it becomes the value of the Text property – It is a string by default – If the user is supposed to enter a number, you’ll have to convert it, just as in a console application Microsoft Visual C# 2010, Fourth Edition 21
  • 22. Adding Labels and TextBoxes to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 22
  • 23. Adding Labels and TextBoxes to a Form (cont'd.) • The form on the next slide is meant to have the user enter two numbers in the TextBoxes • When the user clicks the Button, the sum of the two numbers will be displayed in label3 • You must create the code to do the addition – It goes in the button1_Click() method Microsoft Visual C# 2010, Fourth Edition 23
  • 24. Adding Labels and TextBoxes to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 24
  • 25. Adding Labels and TextBoxes to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 25
  • 26. Adding Labels and TextBoxes to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 26
  • 27. Adding Labels and TextBoxes to a Form (cont'd.) Microsoft Visual C# 2010, Fourth Edition 27
  • 28. Naming Forms and Controls • Provide reasonable Name property values for all the controls you place on a Form – Conventionally, start control names with a lowercase letter and use camel casing – Start Form names with an uppercase letter and use camel casing • A Form is a class, and C# class names conventionally start with an uppercase letter – Use the type of object in the name • To rename a control after you have generated code for it, use the code refactoring feature Microsoft Visual C# 2010, Fourth Edition 28
  • 29. Naming Forms and Controls (cont'd.) Microsoft Visual C# 2010, Fourth Edition 29
  • 30. Naming Forms and Controls (cont'd.) • When you click Rename, a dialog box opens – Type the new method name • A Preview Changes dialog box will highlight the change – Confirm the change by clicking Apply Microsoft Visual C# 2010, Fourth Edition 30
  • 31. Naming Forms and Controls (cont'd.) Microsoft Visual C# 2010, Fourth Edition 31
  • 32. Correcting Errors • As in console-based programs, you will often generate syntax errors • If you build or run a program with an error, you will see “Build failed” in the lower-left corner of the IDE • You will also see an error dialog box – Always click No in response to “Would you like to continue and run the last successful build?” • Errors will be listed in the error list at the lower-left corner of the screen • Double-clicking an error message will take you to the location in the code where the error was found Microsoft Visual C# 2010, Fourth Edition 32
  • 33. Correcting Errors (cont'd.) Microsoft Visual C# 2010, Fourth Edition 33
  • 34. Correcting Errors (cont'd.) Microsoft Visual C# 2010, Fourth Edition 34
  • 35. Correcting Errors (cont'd.) • When you are working in the Form Designer, it is easy to inadvertently double-click a control and create an event-handling method you don’t want – You can leave the event-handling method empty, but that’s considered bad form – You cannot just delete the method because, behind the scenes, other code will have been created that refers to the method – Instead, go to the Properties window of the control, and then click on its Events button, select the button you want to eliminate, and delete the method name Microsoft Visual C# 2010, Fourth Edition 35
  • 36. Correcting Errors (cont'd.) Microsoft Visual C# 2010, Fourth Edition 36
  • 37. Deciding Which Interface to Use • You have learned to create: – Console applications – GUI applications • Both types contain basic building blocks • GUI applications – Look “snazzier” and are easy to use – GUI applications take longer to develop • Console applications – Simpler; may be better when learning new logical constructs Microsoft Visual C# 2010, Fourth Edition 37
  • 38. You Do It • Working With the Visual Studio IDE • Providing Functionality for a Button • Adding a Second Button to a Form Microsoft Visual C# 2010, Fourth Edition 38
  • 39. Summary • Forms are GUI objects that provide an interface for collecting, displaying, and delivering information • The Toolbox displays a list of available controls you can add to a Form – This list includes Button, CheckBox, and Label • Labels are controls that you use to display text to communicate with an application’s user • Provide reasonable Name property values for all the controls you place on a Form Microsoft Visual C# 2010, Fourth Edition 39
  • 40. Summary (cont’d.) • If you build or run a program that contains a syntax error, you see “Build failed” in the lower-left corner of the IDE and an error dialog box • Both console and GUI applications can contain variables and constants, decisions, loops, arrays, and calls to other methods – GUI applications • Look “snazzier” • Contain controls that a user can manipulate with a mouse • Usually take longer to develop Microsoft Visual C# 2010, Fourth Edition 40