Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sep-05 Slide:1 ActiveX Controls in VB ActiveX Controls in VB6.

Similar presentations


Presentation on theme: "Sep-05 Slide:1 ActiveX Controls in VB ActiveX Controls in VB6."— Presentation transcript:

1 Sep-05 Slide:1 ActiveX Controls in VB ActiveX Controls in VB6

2 Sep-05 Slide:2 ActiveX Controls in VB What are ActiveX Controls? Custom UI Controls Which you can design and add to the toolbox And then use in applications

3 Sep-05 Slide:3 ActiveX Controls in VB Creating Simple ActiveX Controls Start with New Project.. ActiveX Control Design/program as if a form Add a project to Group – test it in that Finally, produce a compiled OCX file For example, a simple clock control..

4 Sep-05 Slide:4 ActiveX Controls in VB The Clock Control 1

5 Sep-05 Slide:5 ActiveX Controls in VB Clock Control 2 It will work by having a Timer Which ticks every second And gets system time And displays it in a label

6 Sep-05 Slide:6 ActiveX Controls in VB Clock Control 3

7 Sep-05 Slide:7 ActiveX Controls in VB Clcok Control 4 - Testing

8 Sep-05 Slide:8 ActiveX Controls in VB Clock Control 5 – Normal exe project added

9 Sep-05 Slide:9 ActiveX Controls in VB Clock Control 6 – Set Test as Startup Or when you Run it it will start in a browser

10 Sep-05 Slide:10 ActiveX Controls in VB Clock Control 7 – The control in use

11 Sep-05 Slide:11 ActiveX Controls in VB Clock control 7 – Give it a name

12 Sep-05 Slide:12 ActiveX Controls in VB Clock Control 8 – Make.ocx file

13 Sep-05 Slide:13 ActiveX Controls in VB Clock Control 8 – Adding Control in a new project

14 Sep-05 Slide:14 ActiveX Controls in VB ActiveX Exercise 1 Make a Clock control like this but.. Have 3 fields showing hour, minute and second Use hour() minute() and second() functions

15 Sep-05 Slide:15 ActiveX Controls in VB Controls with properties Most controls have properties used for design Example background colour of textbox And properties for user input Such as text in a text box ActiveX usually need the same

16 Sep-05 Slide:16 ActiveX Controls in VB ActiveX Controls are like Classes (as are forms) They have methods They have private data members They have property let and get routines Can set up events

17 Sep-05 Slide:17 ActiveX Controls in VB Two 'users' of custom controls One user is the programmer who uses the control in a form design The other is the final end-user who uses that form You have to write code for both types of user

18 Sep-05 Slide:18 ActiveX Controls in VB Properties modified at design-time Need public property Let and Get and private data member for internal representation But property values differ between control instances and must 'persist' when Form not in memory so must be written to disc somehow actually stored in the.frm file this persistence is not automated

19 Sep-05 Slide:19 ActiveX Controls in VB Example – a spinner control Input integer values Buttons to increase/decrease value Need a StepSize property

20 Sep-05 Slide:20 ActiveX Controls in VB End-user code Private Sub Command1_Click() Text1.Text = CInt(Text1.Text) + StepSize End Sub Private Sub Command2_Click() Text1.Text = CInt(Text1.Text) - StepSize End Sub

21 Sep-05 Slide:21 ActiveX Controls in VB Dim ssize As Integer Public Property Let StepSize(val As Integer) ssize = val PropertyChanged "StepSize" End Property Public Property Get StepSize() As Integer StepSize = ssize End Property Private Sub UserControl_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty "StepSize", StepSize, 0 End Sub Private Sub UserControl_ReadProperties(PropBag As PropertyBag) StepSize = PropBag.ReadProperty("StepSize", 0) End Sub Private Sub UserControl_Initialize() Text1.Text = 0 End Sub Designer-user code

22 Sep-05 Slide:22 ActiveX Controls in VB Designer use

23 Sep-05 Slide:23 ActiveX Controls in VB.FRM contents VERSION 5.00 Object = "*\AspinnerProject.vbp" Begin VB.Form Form1.. ScaleWidth = 4680 StartUpPosition = 3 'Windows Default Begin Project1.UserControl1 UserControl12 Height = 855 Left = 840.. _ExtentY = 1508 StepSize = 9 End Begin Project1.UserControl1 UserControl11 Height = 855.. _ExtentY = 873 StepSize = 5 End..

24 Sep-05 Slide:24 ActiveX Controls in VB ActiveX Exercise 2 Write a 'slider' control for numeric input When user drags mouse from area, input is mouse Y Have textbox and pictureBox Program the mouseMove event of the PictureBox, use the Y parameter Once working.. add a scale property set at design-time Then expose a 'Value' property which allows access to the number in the (Let and Get) and read/write

25 Sep-05 Slide:25 ActiveX Controls in VB Adding Events to controls A control can make an event occur This would be a 'custom' event for the control Designer can then program an event-handler for it For example, in the spinner control, could hav ea BadKey event if non-digit key pressed..

26 Sep-05 Slide:26 ActiveX Controls in VB Control with Event.. Public Event Badkey().. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Or KeyCode = 8 Then Exit Sub 'Enter or backspace If KeyCode 57 Then ' not 0 to 9 RaiseEvent Badkey End If End Sub

27 Sep-05 Slide:27 ActiveX Controls in VB Designer writes event-handler

28 Sep-05 Slide:28 ActiveX Controls in VB ActiveX Control Exercise 3 Add a 2Click event to the slider control Triggered when picturebox double-clicked As designer, use it to zero the value


Download ppt "Sep-05 Slide:1 ActiveX Controls in VB ActiveX Controls in VB6."

Similar presentations


Ads by Google