Tutorial 7: Building A Ticker Activex Control With The Activex Control Wizard by Michael Rounding
Tutorial 7: Building A Ticker Activex Control With The Activex Control Wizard by Michael Rounding
by Michael Rounding
This pages show you how to use the VB wizard to create a custom
ticker control. It illustrates the VB wizard in detail, how properties can
be dispatched to existing controls within your own control, and how
completely new properties can be created. It also shows an interesting
(even though its simple) new type of control! The actual ticker
example is from Chapter 5 of Custom Controls Library by Rod
Stephens (O'Reilly Press).
BorderStyle Property
Click Event
DblClick Event
Enabled Property
Font Property
ForeColor Property
Figure 5: select interface members dialog
6. The next dialog you get is the Create Custom Interface
Members dialog. In it, you can add your own properties or
methods that might not come as predefined things in VB. You
want to add the following members (guess what? click the New
button in Figure 6):
AutoSize Property
Caption Property
Interval Property
RepeatSpacing Property
XChange Property
Figure 6: create some custom interface members!
7. In the next dialog, you get to map all of your properties and
events (if you want) to specific controls and member methods /
properties thereof. Below is a list of what you should map for this
ticker control thing:
Public Name Maps to Control Maps to Member
AutoSize (none)
Caption (none)
Enabled (none)
RepeatSpacing (none)
XChange (none)
determines whether
the control resizes
AutoSize Boolean 0 R/W R/W
itself to fit the text
displayed
determines whether
Enabled Boolean 0 R/W R/W the control is enabled
to scroll text
The Code
Okay, the complete code is spat out here. Here's how to read it:
• Code generated by VB will appear as greyed out.
• Code that you need to add will appear as normal bolded VB
code. Rock on!
Option Explicit
Dim X As Single
Dim CaptionWidth As Single
CaptionWidth = TextWidth(m_Caption)
If CaptionWidth > 0 And Ambient.UserMode Then
tmrTicker.Enabled = m_Enabled
Else
tmrTicker.Enabled = False
End If
resizing = True
Size ScaleX(TextWidth(m_Caption) - ScaleWidth, vbPixels, vbTwips) +
Width, _
ScaleY(TextHeight(m_Caption) - ScaleHeight, vbPixels, vbTwips) +
Height
resizing = False
m_AutoSize = m_def_AutoSize
m_Caption = m_def_Caption
Set Font = Ambient.Font
m_RepeatSpacing = m_def_RepeatSpacing
m_XChange = m_def_XChange
skip_redraw = False
If Ambient.UserMode Then tmrTicker.Enabled = m_Enabled
SizeControl ' Resize if necessary.
DrawText ' Redraw.
End Sub
Private Sub UserControl_Paint()
DrawText
End Sub
skip_redraw = False
If Ambient.UserMode Then tmrTicker.Enabled = m_Enabled
SizeControl ' Resize if necessary.
DrawText ' Redraw.
End Sub