280 likes | 461 Vues
المحاضرة الثالثة. كيانات برمجة البيزك المرئي Visual Basic Programming Objects By Hitham M. Abo Bakr. In the Previous Lectures. Events in Programming VB . For Every VB Control a number of events, A programmer can implement some event by writing a code for these events
E N D
المحاضرة الثالثة كيانات برمجة البيزك المرئي Visual Basic Programming Objects By Hitham M. Abo Bakr
Events in Programming VB • For Every VB Control a number of events, A programmer can implement some event by writing a code for these events • To Write event code, we need to open Code Window : • From View -> Code • Or double click on any control in the selected form
Code Window Select Control Select events
Event Procedure • Example: Label1.Caption = "Mouse coordinates are x= " & X & "y= " & Y Call event from another Event Private Sub Command1_Click() Label2.Caption = "The time now is" & Now End Sub Private Sub Form_Click() Command1_Click End Sub
Menus and Toolbars Menu Toolbar Is a simple tool to access the program functionality
Creating Menus To Create Menus in Visual Basic, We use Menu Editor tool “tool ->Menu Editor or Ctrl-E
Build Simple Menu • We need to know what is the : • Caption • Name • Visible • Enable • Shortcut • Insert • Multilevel Menu
Writing Code • The only available event for menu items is the click event • Example
ToolBars To Create a toolbar we have to follow the following steps
Creating Toolbar Steps Example Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) If Button.Index = 1 Then MsgBox "Button 1 clicked" ElseIfButton.Index = 2 Then MsgBox "Button 2 clicked" ElseIfButton.Index = 3 Then MsgBox "Button 3 clicked“ End If
Dialog Boxes Dialog Boxes is a window for Display information for the user and receive data from him.
MsgBox function return values • The MsgBox function has the following return values:
Input Box Dim Response As String ' Run the Input Box. Response = InputBox("Number Entry" & vbCrLf & "from 1 and not greater than 100)", "Enter a number.") If ((Val(Response) <= 0) Or (Val(Response) > 100)) Then MsgBox ("invalid number") Else MsgBox ("Valid number") End If
Built-in Dialog Boxes To deal with Built-in Dialog Boxes you have to add a new component