creating a control

Post

Posted
Rating:
#1 (In Topic #385)
Regular
bill-lancaster is in the usergroup ‘Regular’
I can create a series of button controls with:-

Code

  for i = 0 to 5
    With hBtn = New Button(Me) As "BtnTest"
      .X = 10 * i
      .Y = 10
      .W = 10
      .H = 10
      .Name = "Btn" & i
      .text = "+"
    End With
  next

How can I access or change the properties of a particular button?
This is the only way I have at the moment:-

Code

Dim hControl As Control
  For Each hControl In Me.Controls
    If hControl.Name = "Btn5" Then hControl.Hide
  Next

Any advice would be welcome
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi Bill,

Try this code (Note I use the 'gb' button on the Forum not the '</>' button to get Gambas code formatting)

Code (gambas)

  1. hBtn As Button
  2. hButtons As New Button[]
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   Dim Label1 As Label
  7.  
  8.   With Label1 = New Label(Me)
  9.     .Height = 28
  10.     .Width = 200
  11.     .Text = "Click a button"
  12.  
  13.  For i = 0 To 5
  14.     With hBtn = New Button(Me) As "BtnTest"
  15.       .X = 50 * i
  16.       .Y = 40
  17.       .W = 50
  18.       .H = 50
  19.       .Name = "Btn" & i
  20.       .text = "+"
  21.     End With
  22.     hButtons.Add(hBtn)
  23.  
  24.  
  25. Public Sub BtnTest_Click()
  26.  
  27. hButtons[0].Text = "H"
  28. hButtons[1].Text = "E"
  29. hButtons[2].Text = "L"
  30. hButtons[3].Text = "L"
  31. hButtons[4].Text = "O"
  32. hButtons[5].Text = "!"
  33.  
  34.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
 That's brilliant!  Thanks Cogier
Online now: No Back to the top
1 guest and 0 members have just viewed this.