ActiveX%20Controls,%20Enumerated%20Constants%20 - PowerPoint PPT Presentation

About This Presentation
Title:

ActiveX%20Controls,%20Enumerated%20Constants%20

Description:

AND Dropping Down in the Property Box. The User's Design View 'This Enum is for this form ONLY ... Foursquare Solutions Inc. www.foursquare.com. Pat Tormey ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 17
Provided by: patto7
Category:

less

Transcript and Presenter's Notes

Title: ActiveX%20Controls,%20Enumerated%20Constants%20


1
ActiveX Controls, Enumerated Constants With
Events and Other VB Stuff
  • Pat Tormey PE
  • Foursquare Solutions Inc.
  • www.foursquare.com

2
How It Looks
One Control, With Several Methods
3
The Users Design View
Added to Your Tools
AND Dropping Down in the Property Box
4
Enums on the User Form
'This Enum is for this form ONLY Private Enum
Display Green 0 Yellow 1 Red 2 StopSign
3 End Enum Display
Enums give you Free Type-ahead
Private Sub cmd_Click(Index As Integer) On Error
Resume Next Select Case Index Case
Display.Green You get Type-a-Head
uscTrafficLight1.Lights Green .. Case
Display.StopSign uscTrafficLight1.Lights
StopSign End Select End Sub
5
Building The Control (I)
Add a New UserControlDrop in Four image Boxes
in a Control Array called Img()They are
all invisible but one...
Name it something you can remember.
6
Building the Control (II)
Stack them all on top of each otherAnd make the
User Control as small as you can
Youll Also want to select a ToolBox Bitmap
property Its on this list...
7
Enums in the Control
Private miFlag As Integer Public Enum Display
Note its Public Here Green 0 Yellow 1
Red 2 StopSign 3 End Enum 'Public Public
Property Let Show(Flag As Display) 'Making this
PUBLIC causes it to show up in the control's
Property's Window as WRITE miFlag Flag
Lights Flag Pass it thru to the Lights Method
End Property
As a parameter Enums Limit the users options
Less error checking...
Code Behind The UserControl
8
Public Methods
Public Property Get Show() As Display 'Making
this PUBLIC causes it to show up in the
control's Property's Window as READ. Show
miFlag End Property
A Public Method It shows up in the Object Browser
Public Sub Lights(Flag As Display) Dim i As
Integer 'The trick here is to be sure only one
light is visible at a time For i 0 To 3
img(i).Visible (Flag i) Next End Sub
9
In the Object Browser
Be sure to add a descriptionIt shows in the
Browser
10
Raising Events
  • Your Control can raise an event that will be
    seen by its parent form
  • Classes can also raise events the same way but
    you must declare them With Events and you can
    not use the New keyword as part of the
    declaration
  • Heres a simple example...

11
The Change of State Event
The Event Change of StateIs Passed to each
forms Icon Property
12
More Event Stuff
It Even Shows up on the ToolBar
13
Creating a PUBLIC Event in the Control
Here is how its done...
Private miFlag As IntegerModule Wide Scope to
share the State
Public Event ChangeState(miFlag as integer) 'If
the state Changes, it lets the world Know Public
Property Get Icon() Just returning the Selected
Icon Set Icon img(miFlag).Picture End Property
14
Raise the Event in Controls Code
Public Sub Lights(State as Integer) Dim i As
Integer On Error Resume Next For i 0 To 3
img(i).Visible (Flag i) Next miFlag Flag
So it can be passed back RaiseEvent
ChangeState(miFlag) End Sub
15
The Users View of the Event
Once added to the Users Form, the Control has
YOUR new Event. And Carries the Parameter you
assigned!
Private Sub uscTrafficLight1_ChangeState(State as
Integer) Set Icon uscTrafficLight1.Icon
Set Form2.Icon uscTrafficLight1.Icon Set
Form3.Icon uscTrafficLight1.Icon Set
Form4.Icon uscTrafficLight1.Icon End Sub
16
Foursquare Solutions Inc.
  • www.foursquare.com
  • Pat Tormey
Write a Comment
User Comments (0)
About PowerShow.com