Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding Controls At Runtime
Message
 
To
16/04/2002 12:31:50
General information
Forum:
Visual Basic
Category:
ActiveX controls
Miscellaneous
Thread ID:
00645508
Message ID:
00645695
Views:
22
I seem to have run into a problem.

I have code to add command buttons in run-time. Each time I
add a button, I increment a counter, and use the count as
the button name, "cmdButton1", "cmdButton2" and so on.



Private WithEvents cmdButton As CommandButton
Public Event ButtonClicked(Index As Integer)

Private Sub cmdButton_Click()
  RaiseEvent ButtonClicked(Val(cmdButton.Tag))
End Sub


Public Sub AddNewButton()

  Dim iButtonIndex As Integer
  Dim iButtonTop As Integer

  iButtonIndex = GetButtonCount() + 1

  sButtonName = "cmdButton" & iButtonIndex
  Set cmdButton = UserControl.Controls.Add("VB.CommandButton", sButtonName, fraControl)

  iButtonTop = UserControl.fraControl.Height - BUTTON_HEIGHT

  cmdButton.Caption = "Button " & iButtonIndex + 1
  cmdButton.Height = BUTTON_HEIGHT
  cmdButton.Width = UserControl.Width - 50
  cmdButton.ZOrder 0
  cmdButton.Tag = iButtonIndex
  cmdButton.Top = iButtonTop

End Sub


The problem is that the event ButtonClicked only seems
to get called for the last button added.


Any idea what I'm doing wrong?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform