Creazione automatica Oggetti

martedì 24 aprile 2012 - 13.39
Tag Elenco Tags  VB.NET

Feroxis Profilo | Junior Member

Non so se è il metodo giusto per farlo, ma ho riscontrato questo errore, e non ne esco fuori.
Questo il codice:

dim ncomm as integer = 10 ' Dimensione e Posizione del primio parametro da inserire textbox Dim mylocation As System.Drawing.Point mylocation.X = 50 mylocation.Y = 20 Dim size1 As Size size1.Width = 200 size1.Height = 28 'Dimensione e Posizione del secondo paramametro da inserire label Dim numericlocation As System.Drawing.Point numericlocation.X = 25 numericlocation.Y = 20 Dim size As Size size.Width = 25 size.Height = 25 'posizione e dimensione 3° parametro da inserire (bottone) Dim mybuttlocasion As System.Drawing.Point mybuttlocasion.X = 300 mybuttlocasion.Y = 20 Dim size2 As Size size2.Width = 150 size2.Height = 25 '4° e 5° parametro 2 label Dim myxloc As System.Drawing.Point myxloc.X = 500 myxloc.Y = 20 Dim myyloc As System.Drawing.Point myyloc.X = 600 myyloc.Y = 20 Dim size3 As Size size3.Width = 50 size.Height = 25 'contatore per loop che servirà anche per assegnare i nomi agli oggetti creati Dim mycounterhttp As Integer mycounterhttp = 1 'distanza y fra gli oggetti Dim mydistance As Integer mydistance = 50 'loop 'ogni giro creerà 3 label 1 bottone e una text box in riga a partire da Y = 20 poi Y += 50 ' il valore ncomm è dato dal numero di rige che viene prima impostato automaticamente da 1 a 10 Do Until mycounterhttp = ncomm + 1 'textbox Dim myhttp As New TextBox myhttp.Name = "myhttp" & mycounterhttp.ToString myhttp.Location = mylocation myhttp.Size = size1 'label conttore grafico 1-2-3-4-5-6-7-8-9-10 in .text Dim mynumeric As New Label mynumeric.Name = "LblNm" & mycounterhttp.ToString mynumeric.Text = mycounterhttp mynumeric.Location = numericlocation mynumeric.Size = size 'bottone per il comando Dim mybutton As New Button mybutton.Name = mycounterhttp mybutton.Text = "Prendi Posizione" & mycounterhttp mybutton.Location = mybuttlocasion mybutton.Size = size2 AddHandler mybutton.Click, AddressOf my_button 'altri 2 label
Dim mylocx As New Label mylocx.Name = "Lx" & mycounterhttp.ToString mylocx.Location = myxloc mylocx.Size = size3 mylocx.Text = "0" Dim mylocy As New Label mylocy.Name = "Ly" & mycounterhttp.ToString mylocy.Location = myyloc mylocy.Size = size3 mylocy.Text = "0"

'crea gli oggetti nel punto specificato
Form_Generato.Panel1.Controls.Add(mylocx) Form_Generato.Panel1.Controls.Add(mylocy)
Form_Generato.Panel1.Controls.Add(mynumeric)
Form_Generato.Panel1.Controls.Add(myhttp)
Form_Generato.Panel1.Controls.Add(mybutton)
'aumenta tutte le posizioni di 50 per il prossimo oggetti
mylocation.Y += mydistance
numericlocation.Y += mydistance
mybuttlocasion.Y += mydistance
myyloc.Y += mydistance
myxloc.Y += mydistance

'+1 al contatore
mycounterhttp += 1
Loop

[/code]

Una volta inviato questo comando, si crea tutto eccetto le ultime due label ovvero:
Dim mylocx As New Label mylocx.Name = "Lx" & mycounterhttp.ToString mylocx.Location = myxloc mylocx.Size = size3 mylocx.Text = "0" Dim mylocy As New Label mylocy.Name = "Ly" & mycounterhttp.ToString mylocy.Location = myyloc mylocy.Size = size3 mylocy.Text = "0"

IN RIFERIMENTO A:
Form_Generato.Panel1.Controls.Add(mylocx) Form_Generato.Panel1.Controls.Add(mylocy)


Sapete Dirmi Niente?

AntCiar Profilo | Expert

ciao.

L'errore sta dove dichiari size3 perchè valorizzi solo ka width ma non la height perchè involontariamente hai messo 'size' al posto di 'size3'


Dim size3 As Size
size3.Width = 50
size.Height = 25


corretto:
Dim size3 As Size
size3.Width = 50
size3.Height = 25

Cristian Barca
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5