Вы находитесь на странице: 1из 6

c 



 
 
 



i  
  

î   
 

 

Now we want that the control will have all the Command Button properties.
lets add the BackColor property. Enter the following code to your form:

Public Property Get BackColor() As OLE_COLOR


BackColor = Command1.BackColor
End Property

Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)


Command1.BackColor() = New_BackColor
PropertyChanged "BackColor"
End Property

Enter the following line to the UserControl_ReadProperties function:


Command1.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)

Enter the following line to the UserControl_WriteProperties function:


Call PropBag.WriteProperty("BackColor", Command1.BackColor, &H8000000F)

The OLE_COLOR is the type of the BackColor property variable,


the same as the Boolean is the type of the Enabled property variable,
and the Integer is the type of the Height property variable.

What we did now is almost the same as we did with the Text property.
The difference is that in the text property we used
a variable (TextVariable) to store the property information.
Here we not using a variable, we read and write the information
directly to the Command1.BackColor property.

The Command1.BackColor property is here our variable that store


the information. Why is that?
Because when the user set the Control BackColor property,
we actually want to set the Command1 BackColor property.
Suppose the user set the Control BackColor to Black.
In that case, We want to set the Command1 BackColor to Black.
So actually, the Control BackColor property is the
Command1 BackColor property.
So instead of reading and writing to variable,
we read and write directly to the Command1 BackColor property.
It's exactly the same thing with all of the other properties.

î 


  
 

Public Property Get Enabled() As Boolean
Enabled = Command1.Enabled
End Property

Public Property Let Enabled(ByVal New_Enabled As Boolean)


Command1.Enabled() = New_Enabled
PropertyChanged "Enabled"
End Property

Public Property Get Font() As Font


Set Font = Command1.Font
End Property

Public Property Set Font(ByVal New_Font As Font)


Set Command1.Font = New_Font
PropertyChanged "Font"
End Property

Public Property Get Picture() As Picture


Set Picture = Command1.Picture
End Property

Public Property Set Picture(ByVal New_Picture As Picture)


Set Command1.Picture = New_Picture
PropertyChanged "Picture"
End Property

Public Property Get DisabledPicture() As Picture


Set DisabledPicture = Command1.DisabledPicture
End Property

Public Property Set DisabledPicture(ByVal New_DisabledPicture As Picture)


Set Command1.DisabledPicture = New_DisabledPicture
PropertyChanged "DisabledPicture"
End Property

Public Property Get MousePointer() As MousePointerConstants


MousePointer = Command1.MousePointer
End Property

Public Property Let MousePointer(ByVal New_MousePointer As MousePointerConstants)


Command1.MousePointer() = New_MousePointer
PropertyChanged "MousePointer"
End Property

Public Property Get MouseIcon() As Picture


Set MouseIcon = Command1.MouseIcon
End Property

Public Property Set MouseIcon(ByVal New_MouseIcon As Picture)


Set Command1.MouseIcon() = New_MouseIcon
PropertyChanged "MouseIcon"
End Property

Public Property Get Caption() As String


Caption = Command1.Caption
End Property
Public Property Let Caption(ByVal New_Caption As String)
Command1.Caption() = New_Caption
PropertyChanged "Caption"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)


Command1.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
Command1.Enabled = PropBag.ReadProperty("Enabled", True)
Set Font = PropBag.ReadProperty("Font", Ambient.Font)
Set Picture = PropBag.ReadProperty("Picture", "")
Set DisabledPicture = PropBag.ReadProperty("DisabledPicture", "")
Command1.MousePointer = PropBag.ReadProperty("MousePointer", 0)
Set MouseIcon = PropBag.ReadProperty("MouseIcon", "")
Command1.Caption = PropBag.ReadProperty("Caption", "Button")
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)


Call PropBag.WriteProperty("BackColor", Command1.BackColor, &H8000000F)
Call PropBag.WriteProperty("Enabled", Command1.Enabled, True)
Call PropBag.WriteProperty("Font", Font, Ambient.Font)
Call PropBag.WriteProperty("Picture", Picture, "")
Call PropBag.WriteProperty("DisabledPicture", DisabledPicture, "")
Call PropBag.WriteProperty("MousePointer", Command1.MousePointer, 0)
Call PropBag.WriteProperty("MouseIcon", Command1.MouseIcon, "")
Call PropBag.WriteProperty("Caption", Command1.Caption, "Button")
End Sub

[   
[ [
As you see, in some of the properties, we use SET instead of GET.
When you want to change the Command Button Picture property,
you press on the Button with the 3 dots on him that
found in the "Picture" cell (Image 17) , and then browse for your picture.

Image 17:
÷

÷
When we want to set property that uses the browse button, we use SET instead of GET.÷

î 


Event KeyDown(KeyCode As Integer, Shift As Integer)
Event KeyUp(KeyCode As Integer, Shift As Integer)
Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)


RaiseEvent KeyDown(KeyCode, Shift)
End Sub

Private Sub Command1_KeyUp(KeyCode As Integer, Shift As Integer)


RaiseEvent KeyUp(KeyCode, Shift)
End Sub

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)


RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)


RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)


RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub

—
   


Private Sub UserControl_Initialize()
End Sub

The code that you will insert to this sub, will run when
the user first place the control on the form on design time,
and on runtime, when the form with the control on it is loaded.

Private Sub UserControl_Show()


End Sub

This event occur instantly after the Initialize event occur.


The initialize event occur After the control is loaded and before
the Control is visible (to the programmer or the user that run the program)
and the Show event occur right after the Control is visible to the programmer/user.

You can browse for other event: At the control's code window,
choose UserControl from the left ComboBox under the title bar,
and choose event with the right ComboBox.

Image 18:
÷
÷


—
   
 
As you probably saw, when you inserted the control to your project,
the control had a default icon on the ToolBox (Image 16) .
To set your own Icon, Add your icon to the control ToolBoxBitmap property.

Image 19:
÷

÷
Some of the controls are invisible at runtime (Like Timer and ImageList).
To set your control to be invisible at runtime,
Set the control InvisibleAtRuntime property to True.

cî

Make an About property, that when the user will
press on the About property cell on the control Properties window,
A message box will show up with your details.

Add the following code to your form:

Public Sub AboutBox()


MsgBox "This is my message", , "This is my title"
End Sub

Now from the menu choose Tools->Procedure Attributes.


Image 20:
÷

÷
From the 'Name' combo box choose AboutBox,
Click on the Advanced button, and from the 'Procedure ID'
choose AboutBox, and press OK.÷

Now a New property has just been added to your control - the About Property.

The End.

Вам также может понравиться