none
Where are my dynamic TextBoxes going? RRS feed

  • Question

  • I am dynamically adding TextBoxes to a panel.  But I never see them.  Everything in the debugger looks right.  The panel.Controls.Count is >0.  The TextBoxes have borders.  The .Text property is non-blank.  I don't know what more to do to figure out why I can't see them.  

    Here's the code which is initializing the TextBoxes and adding them to the panel.

    ''' <summary>
        ''' initialize the StringInfo Textbox and add it to the form (panel)
        ''' </summary>
        ''' <param name="si"></param>
        ''' <remarks></remarks>
        Public Sub AddStrTbxToForm(ByRef si As StringInfo)
            With si.tbx
                .Font = New Font("Consolas", 10)
                .Width = 400
                .Location = New Point(2, 2 + (pnl1.Controls.Count * 30))
            End With
    
            For Each Str As String In si.tags.Values
                si.tbx.AppendText(Str & " ")
            Next
    
            pnl1.Controls.Add(si.tbx)
    
        End Sub

    If anyone has any ideas I will be grateful for them.  Thanks,  Bob

    Friday, November 15, 2013 12:13 AM

Answers

All replies

  • Well, I finally got to the bottom of this and I am astounded.  There are things I didn't mention in my original post because they just didn't seem to matter at all.  Obviously they do matter but why is sure beyond me.

    The code posted above is part of a form.  It's called by a class constructor.  The class constructor is called by the form.  Why shouldn't that work?  And the really crazy thing is that using the debugger it all appears to be working.  

    If this doesn't work, and it apparently doesn't, shouldn't I at least get an exception?

    Does anyone have any insight?

    Thanks,  Bob

    Friday, November 15, 2013 3:47 AM
  • Hi,Bob

    I reproduced your project and found everything was ok in my project. The si.tbx can be added to

    the panel successfully. Would mind upload your project to skyDrive and share a link in the forum?

    I want to test why the problem occured!

    Best Wishes!


    Friday, November 15, 2013 8:34 AM
  • Set pnl1.AutoSize = true. May be your panel is too small to show your controls.

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Friday, November 15, 2013 9:47 AM
  • Hi Jeffer and thanks for you interest in my problem.

    I cannot make the entire project public but I will try to code an example.  I've tried that but my first attempt has failed to reproduce the problem.  But it is also an oversimplification.  

    A fuller explanation of the flow is:  formA invokes formB; then a formB button click routine calls a constructor which calls a formB method which adds a control to formB.  It shouldn't be a lot of work but I have more pressing things which I have to get to this morning.

    Thanks,  Bob

    Friday, November 15, 2013 2:30 PM