Week 2 windows programming
Download
1 / 58

Week 2: WINDOWS PROGRAMMING - PowerPoint PPT Presentation


  • 157 Views
  • Uploaded on

Week 2: WINDOWS PROGRAMMING. Chapter 15 in “Beginning Visual C# 2010” ebook Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook. Week 2: WINDOWS PROGRAMMING. Working with Windows Forms. CONTROLS. When you work with Windows Forms, you are working with the

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

PowerPoint Slideshow about 'Week 2: WINDOWS PROGRAMMING' - julie


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
Week 2 windows programming

Week 2: WINDOWS PROGRAMMING

Chapter 15 in “Beginning Visual C# 2010” ebook

Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook


Week 2 windows programming1

Week 2: WINDOWS PROGRAMMING

Working with Windows Forms


Controls
CONTROLS

When you work with Windows Forms, you are working with the

System.Windows.Forms namespace

Most controls in .NET derive from the System.Windows.Forms.Control class

Many of these classes are themselves base classes for other controls, as is the case with the Label and TextBoxBase classes

Windows Programming 1 Basic Windows Programming Slide 3


Controls1
CONTROLS

Windows Programming 1 Basic Windows Programming Slide 4


Properties common control class properties
PropertiesCommon Control Class Properties

Windows Programming 1 Basic Windows Programming Slide 5


Properties common control class properties1
Properties Common Control Class Properties

Windows Programming 1 Basic Windows Programming Slide 6


Adding controls to a windows form
Adding Controls to a Windows Form

  • Adding Controls by Using the Windows Forms Designer

  • Adding Controls Programmatically

Windows Programming 1 Basic Windows Programming Slide 7


Adding controls programmatically
Adding Controls Programmatically

  • 1. Create a private variable to represent each of the controls you want to place on the form

  • 2. In the form, place code to instantiate each control and to customize each control, using its properties, methods, or events.

  • 3. Add each control to the forms control collection.

Windows Programming 1 Basic Windows Programming Slide 8


Exam page 113
Exam (page 113)

Windows Programming 1 Basic Windows Programming Slide 9


Handling control events
Handling Control Events

  • Add controls to a Windows form.

    • Set properties on controls.

    • Load controls dynamically.

    • Write code to handle control events and add the code to a control.

Windows Programming 1 Basic Windows Programming Slide 10


Handling control events ex
Handling Control Events_Ex

Windows Programming 1 Basic Windows Programming Slide 11


Handling control events1
HANDLING CONTROL EVENTS

Windows Programming 1 Basic Windows Programming Slide 12


Handling control events2
HANDLING CONTROL EVENTS

Windows Programming 1 Basic Windows Programming Slide 13


Week 2 windows programming

HANDLING CONTROL EVENTS

Windows Programming 1 Chapter 15:Basic Windows Programming Slide 14


Week 2 windows programming

HANDLING CONTROL EVENTS

Windows Programming 1 Chapter 15:Basic Windows Programming Slide 15


Common windows forms controls
COMMON WINDOWS FORMSCONTROLS

Windows Programming 1 Basic Windows Programming Slide 16


Naming rules
Naming Rules

  • Always use standard names for objects

  • No spaces or punctuation marks

  • 3 letter lowercase prefix identifies control type

    • Button-btn

    • Label-lbl

    • Form-frm

  • If multiple words capitalize 1st letter of each word

  • Each object name is an identifier

    • Can contain letters, digits, and underscores (_)

    • Cannot start with digits

    • Can start with the at symbol (@)

  • Windows Programming 1 Basic Windows Programming Slide 17


    Recommended naming

    Object Class Prefix Example

    Form frm frmDataEntry

    Button btn btnExit

    TextBox txt txtPaymentAmount

    Label lbl lblTotal

    Radio Button rad radBold

    CheckBox chk chkPrintSummary

    PictureBox pic picLandscape

    ComboBox cbo cboBookList

    ListBox lst lstIndegredients

    GroupBox grb grbColor

    Recommended Naming

    Windows Programming 1 Basic Windows Programming Slide 18


    Windows forms
    Windows Forms

    Windows Forms is the basic building block of the UI

    It provides a container that hosts controls and menus and enables you to present an application in a familiar and consistent fashion

    You can add and configure additional forms at design time, or you can create instances of predesigned forms in code at run time.

    Windows Programming 1 Basic Windows Programming Slide 19


    Windows forms some properties of the form class
    Windows FormsSome Properties of the Form Class

    Windows Programming 1 Basic Windows Programming Slide 20


    Windows forms some properties of the form class1
    Windows FormsSome Properties of the Form Class

    Windows Programming 1 Basic Windows Programming Slide 21


    Windows forms some properties of the form class2
    Windows FormsSome Properties of the Form Class

    Windows Programming 1 Basic Windows Programming Slide 22


    Setting the title of the form
    Setting the Title of the Form

    To change the title of a form at run time, set the Text property of the form in code, as shown in the following code:

    Windows Programming 1 Basic Windows Programming Slide 23


    Setting the border style of the form
    Setting the Border Style of the Form

    Windows Programming 1 Basic Windows Programming Slide 24


    Specifying the startup location of the form
    Specifying the Startup Location of the Form

    Windows Programming 1 Basic Windows Programming Slide 25


    Keeping a form on top of the user interface
    Keeping a Form on Top of the User Interface

    Module2- 21

    TopMost = True

    FormBorderStyle = None;

    StartPosition = CenterToScreen;

    Windows Programming 1 Basic Windows Programming Slide 26


    Opacity and transparency in forms
    Opacity and Transparency in Forms

    The Opacity property to create striking visual effects in your form

    Values between 0 percent and 100 percent

    result in a partially transparent form

    Windows Programming 1 Basic Windows Programming Slide 27


    Setting the startup form
    Setting the Startup Form

    1. In Solution Explorer, double-click Program.cs to view the code. The code window opens.

    2. Locate the Main method and then locate the line that reads:Application.Run(new Form());where Form represents the name of the form that is currently the startup form.

    3. Change Form to the name of the form you want to set as the startup form.

    Windows Programming 1 Basic Windows Programming Slide 28


    Control properties and layout
    Control Properties and Layout

    • Common properties

      • Derive from class Control

      • Text property

        • Specifies the text that appears on a control

      • Focus method

        • Transfers the focus to a control

        • Becomes active control

      • Enable property

        • Indicate a control’s accessibility

    Windows Programming 1 Basic Windows Programming Slide 29


    Control properties and layout1
    Control Properties and Layout

    • Visibility control

      • Hide control from user

    • Anchor property

      • Anchoring control to specific location (corner)

      • Unanchored control moves relative to the position

      • Docking allows control to spread itself along and entire side

      • Both options refer to the parent container

    Windows Programming 1 Basic Windows Programming Slide 30


    Control properties and layout2
    Control Properties and Layout

    Before resize

    After resize

    Constant distance to left and top sides

    Fig. 12.11 Anchoring demonstration.

    Windows Programming 1 Basic Windows Programming Slide 31


    Control properties and layout3
    Control Properties and Layout

    Darkened bar indicates to which wall control is anchored

    Click down-arrow in Anchor property to display anchoring window

    Fig. 12.12 Manipulating the Anchor property of a control.

    Windows Programming 1 Basic Windows Programming Slide 32


    Control properties and layout4
    Control Properties and Layout

    Control expands along top portion of the form

    Fig. 12.13 Docking demonstration.

    Windows Programming 1 Basic Windows Programming Slide 33


    Control properties and layout5
    Control Properties and Layout

    Windows Programming 1 Basic Windows Programming Slide 34


    Labels and linklabel controls
    Labelsand LinkLabel controls

    • Labels : The standard Windows label

    • LinkLabel: A label similar to the standard one but that presents itself as an Internet link (a hyperlink)

      • You don’t need to add event handling code for a standard Label

      • Some extra code is needed to enable users clicking it to go to the target of the LinkLabel

    Windows Programming 1 Basic Windows Programming Slide 35


    Common label control properties
    Common Label Control Properties

    Windows Programming 1 Basic Windows Programming Slide 36


    Common label control properties1
    Common Label Control Properties

    Windows Programming 1 Basic Windows Programming Slide 37


    Button control
    Button Control

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 38


    Lable textbox button control
    Lable –Textbox – Button Control

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 39


    Linklable demo
    LinkLable - Demo

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 40


    Linklable demo1
    LinkLable - Demo

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 41


    Textboxes and richtextbox
    TextBoxes and RichTextBox

    • The .NET Framework comes with two basic controls to take text input from users:

    • TextBox and RichTextBox.

      • Both controls are derived from a base class called TextBoxBase, which itself is derived from Control.

    Windows Programming 1 Basic Windows Programming Slide 42


    Common textbox control properties
    Common TextBox Control Properties

    Windows Programming 1 Basic Windows Programming Slide 43


    Common textbox control properties1
    Common TextBox Control Properties

    Windows Programming 1 Basic Windows Programming Slide 44


    The richtextbox control
    THE RICHTEXTBOX CONTROL

    Like the normal TextBox, the RichTextBox control is derived from TextBoxBase

    Whereas a TextBox is commonly used for the purpose of obtaining short text strings from the user

    The RichTextBox is used to display and enter formatted text (e.g., bold, underline, and italic). It does so using a standard for formatted text called Rich Text Format, or RTF.

    Windows Programming 1 Basic Windows Programming Slide 45


    Common richtextbox control properties
    Common RichTextBox Control Properties

    Windows Programming 1 Basic Windows Programming Slide 46


    Common richtextbox control properties1
    Common RichTextBox Control Properties

    Windows Programming 1 Basic Windows Programming Slide 47


    Richtextbox demo
    RichTextbox - demo

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 48


    Richtextbox demo1
    RichTextbox - demo

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 49


    Week 2 windows programming

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 50


    Week 2 windows programming2

    Week 2: WINDOWS PROGRAMMING

    Controls for displaying pictures


    The picturebox control
    The PictureBox Control

    The PictureBox control is the basic control used for displaying images in the user interface, and it can display pictures in a variety of formats, including .bmp, .jpg, .gif, metafiles, and icons.

    Windows Programming 1 Basic Windows Programming Slide 52


    The picturebox control1
    The PictureBox Control

    Windows Programming 1 Basic Windows Programming Slide 53


    The picturebox control2
    The PictureBox Control

    At run time, you can set the Image property to an instance of an image, as shown in the following example:

    Windows Programming 1 Basic Windows Programming Slide 54


    Picturebox demo
    Picturebox - demo

    Module 2- 6

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 55


    Picturebox demo1
    Picturebox - demo

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 56


    Picturebox demo2
    Picturebox - demo

    Module 2- 11

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 57


    Picturebox demo3
    Picturebox - demo

    Windows Programming 1 Chapter 15:Basic Windows Programming Slide 58