Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding Controls At Runtime
Message
 
À
16/04/2002 12:31:50
Information générale
Forum:
Visual Basic
Catégorie:
Contrôles ActiveX
Divers
Thread ID:
00645508
Message ID:
00645695
Vues:
23
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform