Inquiridor
Criar objeto em tempo de execução não mostra objeto criado

Pergunta
-
Bom dia pessoal
Estou com um problema com criação de controles em tempo de execução.
Os controle são criados em tempo de execução usando dados de uma tabela e carregada em um array.
O problema acontece quando não a interação nem uma do usuário, os controle não aparecem, no meu forme já criado e carregado.
E quando faço o processo através de um Button os objetos criado aparece de forma correta, e quando não a a iteração do usuário os mesmos não aparecem.
alguém sabe por que isto ocorre?
agradeço a ajuda
t+
Nilson Morgenstern
Todas as Respostas
-
-
-
Segue o código:
Este código funciona perfeitamente, pois foi um que montei para teste.
Quando este mesmo código que esta dentro de minha aplicação não funciona.
Public Class Form1 Dim Criado As Boolean Dim MouseX, MouseY As Integer Dim LinhaX, LinhaY, ObjCriado As Long Dim VezAparecer As Long Dim ArrayEntrega As Object = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} 'Variavel CaminhoAplication Carega o caminho da pasta da Aplicação Public CaminhoAplication As String = My.Application.Info.DirectoryPath & "\" Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.Escape Then Close() ElseIf e.KeyCode = Keys.F1 Then btNovaEntrega_Click(btNovaEntrega, New EventArgs) End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Sub CriaArrayControl() 'link do tutorial 'http://fabner.wordpress.com/2009/06/30/array-de-controles-no-vb-net/ Dim Cont As Long = 0 'Controls.Clear() Panel2.Controls.Clear() LinhaX = 0 LinhaY = 0 ObjCriado = 0 Dim MesaA As Integer = 0 Dim objBotoes() As Button = Nothing Dim intIndice As Integer Dim Mesa As Integer ' Dim intY As Integer = 1 LinhaY = 1 LinhaX = 10 'Dim cmd As New NpgsqlCommand("Select ""Mesa"" From ""Mesa"" Order By ""Mesa"" Asc", bd) 'Dim rs As NpgsqlDataReader = cmd.ExecuteReader 'While rs.Read For Cont = 0 To UBound(ArrayEntrega) If IsNumeric(ArrayEntrega(Cont)) Then Mesa = ArrayEntrega(Cont) ReDim Preserve objBotoes(Mesa) objBotoes(Mesa) = New Button With objBotoes(Mesa) 'intY += 30 .Name = Mesa .Text = Mesa '.AutoSize = True .Location = New Point(LinhaX, LinhaY) .Tag = Mesa .Width = 125 .Height = 114 .TextAlign = ContentAlignment.BottomRight .Visible = True 'Abaixo tem que colocar para ver quando a mesda esta ocupada 'a fazer as adaptações 'MesaA = RetDadosNumero("Select Count(*) From ""MesaOP"" Where ""Mesa""=" & Mesa & " And ""Caixa""=" & DataCaixa(1) & " And ""Fechada""='N' And ""Estorno""='N'") If MesaA = 0 Then 'MesaA = 1 .Image = Bitmap.FromFile(CaminhoAplication & "\Entrega.png") '.TextAlign = ContentAlignment.BottomRight Else ' MesaA = 0 .Image = Bitmap.FromFile(CaminhoAplication & "\Entrega.png") ' .TextAlign = ContentAlignment.BottomRight End If End With AddHandler objBotoes(Mesa).Click, AddressOf btMersa_Click AddHandler objBotoes(Mesa).MouseHover, AddressOf btMersa_MouseHover AddHandler objBotoes(Mesa).MouseLeave, AddressOf btMersa_MouseLeave Panel2.Controls.Add(objBotoes(Mesa)) ' Panel2.Add(Panel2, objBotoes(Mesa)) LinhaX += (125 + 10) ObjCriado += 1 If ObjCriado = 7 Then ObjCriado = 0 LinhaX = 10 LinhaY += (114 + 5) End If End If Next If Cont = 0 Then Panel2.Controls.Clear() Else Dim Obj As Long = Panel2.Controls.Count 'InitializeComponent() End If Criado = True End Sub Private Sub btMersa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub btMersa_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) End Sub Private Sub btMersa_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) End Sub Private Sub btNovaEntrega_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btNovaEntrega.Click Dim FormCt As New Form3 FormCt.ShowDialog() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.sslblDataHora.Text = DateTime.Now.ToString("HH:mm:ss") & vbCrLf & DateTime.Now.ToString("dd/MM/yyyy") End Sub Private Sub btFecha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btFecha.Click End End Sub End Class
agradeço a ajuda.
Nilson Morgenstern