Написал простой класс - кнопку, с одним единственным внешним событием - "OnClick()":
- Код: Выделить всё
'//Class - GButton
Private Type Point
x As Integer
y As Integer
End Type
Private xy As Point
Private pic As String
Private dep As Byte
Private dist As Byte
Private depx As Byte
Private cont As Form
Public WithEvents Im As VB.Image
Public Event OnClick()
Public Property Get xPoint() As Integer
xPoint = xy.x
End Property
Public Property Let xPoint(ByVal Value As Integer)
xy.x = Value
End Property
Public Property Get yPoint() As Integer
yPoint = xy.y
End Property
Public Property Let yPoint(ByVal Value As Integer)
xy.y = Value
End Property
Public Property Get sPic() As String
sPic = pic
End Property
Public Property Let sPic(ByVal Value As String)
pic = Value
End Property
Public Property Get sDep() As Byte
sDep = dep
End Property
Public Property Let sDep(ByVal Value As Byte)
dep = Value
End Property
Public Property Get sDepx() As Byte
sDepx = depx
End Property
Public Property Let sDepx(ByVal Value As Byte)
depx = Value
End Property
Public Property Get sDist() As Byte
sDist = dist
End Property
Public Property Let sDist(ByVal Value As Byte)
dist = Value
End Property
Public Sub Constructor(Frm As Form, PicPath As String, PicDist As Byte, x As Integer, y As Integer)
Set cont = Frm
pic = PicPath
Im.Picture = LoadPicture(pic)
Im.Tag = 0
dist = PicDist
dep = 25
depx = 2
xy.x = x
xy.y = y
Im.Move xy.x, xy.y
Im.Visible = True
Im.Stretch = True
End Sub
Private Sub Class_Initialize()
xy.x = 0
xy.y = 0
pic = ""
dep = 0
depx = 0
Set container = Nothing
End Sub
Public Sub Hide(Flag As Boolean)
If Flag Then
Im.Visible = False
Else: Im.Visible = True
End If
End Sub
Public Sub SetPicture(Path As String)
pic = Path
Im.Picture = LoadPicture(pic)
End Sub
Private Sub Im_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 And Im.Tag = 0 Then
Im.Tag = 1
Im.Top = (Im.Top + dep)
Im.Left = (Im.Left + dep)
Im.Width = (Im.Width - (dep * depx))
Im.Height = (Im.Height - (dep * depx))
End If
End Sub
Private Sub Im_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 And Im.Tag = 1 Then
Im.Tag = 0
Im.Top = (Im.Top - dep)
Im.Left = (Im.Left - dep)
Im.Width = (Im.Width + (dep * depx))
Im.Height = (Im.Height + (dep * depx))
End If
End Sub
Private Sub Im_Click()
RaiseEvent OnClick
End Sub
Код на форме:
- Код: Выделить всё
Dim WithEvents GB As GButton
Private Sub GB_OnClick()
Me.Cls
Me.Print "ClassImageClicked"
End Sub
Private Sub Form_Load()
Set GB = New GButton
Set GB.Im = Controls.Add("VB.Image", "Im", Me)
Call GB.Constructor(Me, App.Path & "\mk1.bmp", 60, 500, 500)
End Sub
Далее необходимо создать несколько таких кнопок в одну линию. Число создаваемых объектов класса заранее не известно. Необходимо объявить их как массив, но "WithEvents" не позволяет это сделать (также как и внутри класса "WithEvents" не дает объявить массив элементов "Image"). Возможно ли это обойти, либо сделать как-то иначе..
Прошу Вашей помощи. Помогите, пожалуйста, разобраться в проблеме.