Acknowledgement - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Acknowledgement

Description:

Double-click on the form or on any of the controls ... Reverse the action of Deactivate() event (e.g. enable buttons) Private Sub Form_Activate ... – PowerPoint PPT presentation

Number of Views:9840
Avg rating:3.0/5.0
Slides: 19
Provided by: richard500
Category:

less

Transcript and Presenter's Notes

Title: Acknowledgement


1
Acknowledgement
  • This presentation was created by
  • Dr. Kurkovsky
  • of Columbus State University

2
Events Outline
  • Code window
  • Form events
  • Events of different controls

3
Code Window
  • To open it
  • Double-click on the form or on any of the
    controls
  • Or right click on the form or on any of the
    controls and select View Code
  • Important
  • Set the Name property of a control before writing
    code for it

Control name
Title bar displays project name and module name
Event
This is where you write code
4
Event Procedures
  • Event procedure runs in the response to an event
    that happens to a form or control.

Declares an event procedure
Name of the control or Form (for the form)
Event name
Marks the end of the event procedure
Your code goes here
5
How to Use Events
  • Events are used to run some code that will
    perform a process based on some user action.
  • Examples
  • Initializing a form or control
  • Changing the properties of a control or a form
  • Making the form close.

Private Sub cmdClose_Click() Unload MeEnd Sub
Private Sub cmdMoveDown_Click()
frmEventsDemo.Top frmEventsDemo.Top 20End
Sub Private Sub cmdMoveUp_Click()
frmEventsDemo.Top frmEventsDemo.Top 20End Sub
6
Common Events
  • Click
  • DblClick
  • Change
  • GotFocus
  • LostFocus
  • KeyPress
  • KeyDown
  • KeyUp
  • MouseDown
  • MouseUp
  • MouseMove

7
Form Events 1
  • Display a form frmFormName Show
  • Form_Initialize()The first event that occurs
    after calling the Show method. Controls are not
    yet loaded into memory. Occurs only once.
  • Form_Load()The second event that occurs after
    calling the Show method. Form and controls are
    already loaded into memory. Occurs only once.
    Typical use
  • Initialize variables
  • Load initial data into controls (e.g. lists)
  • Private Sub Form_Load() cmdSave.Enabled
    FalseEnd Sub

8
Form Events 2
  • Form_Resize()Occurs whenever the form is resized
    by the user or by the source code. Typical use
  • Shrink or move controls on the form
  • Prevent the form from being too large or too
    small
  • Private Sub Form_Resize() If Me.Height gt 3000
    Then Me.Height 3000 End If If Me.Width
    gt 6000 Then Me.Width 6000 End IfEnd
    Sub

9
Form Events 3
  • Form_Activate()Occurs when the form gets focus.
    Typical use
  • Update the status bar of the application
  • Reverse the action of Deactivate() event (e.g.
    enable buttons)
  • Private Sub Form_Activate() cmdClose.Enabled
    TrueEnd Sub
  • Form_Deactivate()Occurs when the form loses
    focus. Typical use
  • Reverse the action of Activate() event (e.g.
    disable buttons)
  • Private Sub Form_Deactivate()
    cmdClose.Enabled FalseEnd Sub

10
Form Events 4
  • Form_QueryUnload()Occurs when the user tries to
    unload the form by clocking the Close
    buttonAlso, event QueryUnload() can be triggered
    by Unload Mestatement. Typical use
  • Ask the user whether s/he wants to close the
    application, save the data, etc.
  • Form_Unload()Occurs before the form is unloaded.
    Typical use
  • Restore the variables to the state prior to
    loading the form.
  • Form_Terminate()The last event to fire when a
    form is unloaded. Typical use
  • Clean up any form variables initialized in
    Form_Initialize() event.

11
Text Box Events
  • TextBox_Change()Occurs when the user changes the
    text inside the text box. Example
  • Enabling the Save button.

12
Command Button Events
  • CommandButton_Click()Occurs when the user clicks
    on the command button or presses the hotkey.
    Example
  • Enabling the Save button,
  • Unloading the form.

13
Option Button Events
  • OptionButton_Click()Occurs when the user clicks
    on a single option button or presses the hotkey.
    Example
  • Enabling the Save button.
  • Private Sub optFemale_Click() cmdSave.Enabled
    TrueEnd Sub
  • Private Sub optMale_Click() cmdSave.Enabled
    TrueEnd Sub

14
Check Box Events
  • CheckBox_Click()Occurs when the user clicks on a
    check box or presses the hotkey. Example
  • Enabling the Save button.
  • Private Sub chk401k_Click() cmdSave.Enabled
    TrueEnd Sub
  • Private Sub chkBonus_Click() cmdSave.Enabled
    TrueEnd Sub
  • Private Sub chkHealth_Click() cmdSave.Enabled
    TrueEnd Sub

15
Picture and Image Control Events
  • Picture_Click()Occurs when the user clicks on a
    picture control. Example
  • Opening another window.
  • Private Sub picMail_Click() frmMessage.Show
    vbModalEnd Sub
  • vbModal optional parameter indicates a modal
    window (dialog box)

16
List Box Events
  • ListBox_Click()Occurs when the user clicks on an
    item in the list box. Example
  • Showing a message with the selected item.
  • Private Sub lstHealth_Click() MsgBox
    "Selected item " _ lstHealth.List(lstHealth
    .ListIndex), _ vbOKOnly, "List Box
    ControlEnd Sub
  • ListBox_ItemCheck()Occurs when the user clicks
    on the checkbox of an item in the list box when
    Style property is set to 1-Check BoxExample
  • Showing a message with the checked item
  • Private Sub lstHealth_ItemCheck(Item As _
    Integer) MsgBox "Checked item " _
    lstHealth.List(Item), _ vbOKOnly, "List
    Box ControlEnd Sub

17
Combo Box Events
  • ComboBox_Change()Occurs if the Style property is
    set to 0-DropDown Combo or 1-Simple Combo when
    the user changes the content of the text box
    component.
  • ComboBox_Click()Occurs when the user clicks on
    an item in the list component. Example
  • Enabling the Save Button
  • Private Sub cboState_Click() cmdSave.Enabled
    True End Sub
  • ComboBox_DropDown()Occurs if the Style property
    is set to 0-DropDown Combo or 2-DropDown List
    when the user opens the drop-down component.

18
Menu Events
  • Menu_Click()Occurs when the user clicks on a
    menu item. Example
  • Closing a window.
  • Private Sub mnuFExit_Click() Unload Me End
    Sub
  • Example
  • Displaying a form
Write a Comment
User Comments (0)
About PowerShow.com