Visual Basic Concepts
A data control needs a user interface to allow the user to move back and forth through the data. In this case, we'll duplicate the functionality and appearance of the familiar Data control using four CommandButtons and a Label control, with a PictureBox to act as a container.
Note This topic is part of a series that walks you through creating sample data source components. It begins with the topic Creating Data Sources.
To add constituent controls to the MyData control
Property | Value |
BackColor | &H80000005 (Window Background) |
Width | 4500 |
Property | Values |
(Name) | cmdFirst; cmdPrev; cmdNext; cmdLast |
Caption | (Empty) |
Picture | First.bmp; Prev.bmp; Next.bmp; Last.bmp |
Style | 1 - Graphical |
Width | 300 |
Note The bitmaps for the Picture property can be found in the same directory as the AXData sample application.
Property | Value |
(Name) | lblCaption |
BackStyle | 0 - Transparent |
Caption | MyData |
Private Sub UserControl_Resize()
Picture1.Move 0, 0, Width, Height
cmdFirst.Move 0, 0, cmdFirst.Width, Height - 60
cmdPrev.Move cmdFirst.Left + cmdFirst.Width, 0, _
cmdPrev.Width, Height - 60
cmdLast.Move (Width - cmdLast.Width) - 60, 0, _
cmdLast.Width, Height - 60
cmdNext.Move cmdLast.Left - cmdNext.Width, 0, _
cmdNext.Width, Height - 60
lblCaption.Height = TextHeight("A")
lblCaption.Move cmdPrev.Left + _
cmdPrev.Width, ((Height - 60) _
/ 2) - (lblCaption.Height / 2), _
cmdNext.Left - (cmdPrev.Left _
+ cmdPrev.Width)
End Sub
This code will execute when the MyData is initialized or whenever it is resized to rearrange the constituent controls and provide a consistent appearance.
Public Property Get Caption() As String
Caption = lblCaption.Caption
End Property
Public Property Let Caption(ByVal NewCaption As String)
lblCaption.Caption = NewCaption
PropertyChanged "Caption"
End Property
Option Explicit
' Enumerations for the BOFAction Property.
Public Enum BOFActionType
adDoMoveFirst = 0
adStayBOF = 1
End Enum
' Enumerations for the EOFAction Property.
Public Enum EOFActionType
adDoMoveLast = 0
adStayEOF = 1
adDoAddNew = 2
End Enum
' Declare object variables for ADO connection
' and Recordset objects.
Private cn As ADODB.Connection
Private WithEvents rs As ADODB.Recordset
' Default Property Values:
Const m_def_RecordSource = ""
Const m_def_BOFAction = BOFActionType.adDoMoveFirst
Const m_def_EOFAction = EOFActionType.adDoMoveLast
Const m_def_ConnectionString = ""
'Property Variables:
Private m_RecordSource As String
Private m_BOFAction As BOFActionType
Private m_EOFAction As EOFActionType
Private m_ConnectionString As String
Private Sub UserControl_InitProperties()
m_RecordSource = m_def_RecordSource
m_BOFAction = m_def_BOFAction
m_EOFAction = m_def_EOFAction
lblCaption.Caption = Ambient.DisplayName
m_ConnectionString = m_def_ConnectionString
Set UserControl.Font = Ambient.Font
End Sub
For More Information See "Drawing the ShapeLabel Control" and "Adding an Event to the ShapeLabel Control" in "Creating an ActiveX Control."
This topic is part of a series that walks you through creating sample ActiveX data sources.
To | See |
Go to the next step | Adding the AXDataSource Project |
Start from the beginning | Creating Data Sources |