Autore Topic: Controlli presenti in una form  (Letto 1242 volte)

Offline andy60

  • Senatore Gambero
  • ******
  • Post: 1.256
    • Mostra profilo
    • https://www.linkedin.com/in/andbertini
Controlli presenti in una form
« il: 03 Febbraio 2008, 10:07:43 »
con il comando Fmain.controls.count si ottiene il numero dei controlli presenti su una form, creati in modalità design...ma come faccio a creare un array con tutti i nomi degli oggetti textbox presenti in una form? Supponendo chiaramente di non averli creati con una routine di questo tipo:

Codice: [Seleziona]
PUBLIC SUB creatextbox()
DIM x AS Integer
DIM hbox[100] AS TextBox
FOR x = 1 TO 5
  hbox[x] = NEW TextBox(FMain)
  hbox[x].text = hbox[x].name
  hbox[x].left = 100
  hbox[x].top = 50 * x
NEXT
END

Offline leo72

  • Amministratore
  • Senatore Gambero
  • *****
  • Post: 2.163
    • Mostra profilo
    • http://www.leonardomiliani.com
Re: Controlli presenti in una form
« Risposta #1 il: 03 Febbraio 2008, 11:00:58 »
Credo che tu debba creare prima un array di Objet in cui poi infilerai i Textbox via via che li crei.

Esemio:

Codice: [Seleziona]

' Gambas class file
PRIVATE CaselleTestuali AS NEW Object[]
PRIVATE CasellaTestuale AS TextBox

PUBLIC SUB _new()
DIM varI AS Integer
DIM varX, varY AS Integer

  varX = 48
  FOR varI = 0 TO 3
    CasellaTestuale = NEW TextBox(ME)
    CasellaTestuale.Name = "CasellaTestuale" & trim(cstr(varI)
    CasellaTestuale.X = CoordinataX+VarX
    CasellaTestuale.Y = 300
    CaselleTestuali.Add(CasellaTestuale)
    varX = varX + 50
  NEXT
END


In questa maniera CaselleTestuali[] contiene tutte le TextBox create, a cui puoi accedere con un indice, es.:
Codice: [Seleziona]

CaselleTestuali[1].Text = "Ciao"
Visita il mio sito personale: http://www.leonardomiliani.com

Offline andy60

  • Senatore Gambero
  • ******
  • Post: 1.256
    • Mostra profilo
    • https://www.linkedin.com/in/andbertini
Re: Controlli presenti in una form
« Risposta #2 il: 03 Febbraio 2008, 12:43:29 »
' Gambas class file

PRIVATE CaselleTestuali AS NEW Object[]
Codice: [Seleziona]
PRIVATE CasellaTestuale AS TextBox

PUBLIC SUB _new()
DIM varI AS Integer
DIM varX, varY, CoordinataX AS Integer
  CoordinataX = 20
  varX = 48
  FOR varI = 0 TO 3
    CasellaTestuale = NEW TextBox(ME)
    CasellaTestuale.Name = "CasellaTestuale" & Trim(CStr(varI))
    CasellaTestuale.X = CoordinataX + VarX + varI * 3
    CasellaTestuale.Y = 300
    CaselleTestuali.Add(CasellaTestuale)
    varX = varX + 50
  NEXT
END

PUBLIC SUB Button1_Click()
DIM n AS Integer
ListBox1.Clear
FOR n = 0 TO 3
  ListBox1.Add(CaselleTestuali[n].Name & " " & CaselleTestuali[n].X & " " & CaselleTestuali[n].Y)
NEXT  
END


in effetti è cosi' come dici te, grande! grazie! :-D