Strange problem with dynamically created control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Strange problem with dynamically created control

  1. #1
    Join Date
    Oct 2006
    Posts
    18

    Strange problem with dynamically created control

    Hi,

    I have a strange behavior with a dynamically created TextBox-Control. The control is created in the handler of the Load-event of a dialog-form like this:

    txtTitel = New System.Windows.Forms.TextBox
    txtTitel.Name = "txtTitel"
    txtTitel.BackColor = Color.White
    txtTitel.ForeColor = Color.Blue
    txtTitel.Location = New System.Drawing.Point(106, 185)
    txtTitel.Size = New System.Drawing.Size(406, 20)
    txtTitel.TabIndex = 7
    txtTitel.Text = ""
    Me.Controls.Add(txtTitel)

    Now the situation is, that in most cases it works fine. But a few of my customers report that the TextBox not appears on their dialog - it's not there! That's all, nothing more to say.

    I appreciate any advice, hints or reports about known pitfalls with dynamically created controls which could explain this (sometimes) strange behavior and how I could fix it (I have to create this control dynamically due to some reasons).

    BTW: The program is built with Visual Basic 2005. And the customers with trouble are spread about the OS's (XP, Vista, 7).

    Many thanks in advance

    Physicus.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: Strange problem with dynamically created control

    I do not know if it would make a difference but I always set the visible property to true and have never saw an issue like you describe.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Oct 2006
    Posts
    18

    Re: Strange problem with dynamically created control

    Hello DataMiser,

    thank you for your reply and your advice.
    Member visible = True should be the default when creating a new control. But you may be right - setting it explicitely to True would be the save way.

    I also thought about doing the creation in an other handler but I think Load() is the best place, isn't it?

    Thank's for your answer.

    Physicus.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: Strange problem with dynamically created control

    I have seen this before, on XP believe it or not!

    I always, always use .Visible = True.

    Do not ask me why this behaviour happens, it just does

    Where to put probably depends on your situation. What I do is to have a separate sub that creates the control(s). This why the Form_Load is not so clogged with the creation of the control.

  5. #5
    Join Date
    Oct 2006
    Posts
    18

    Re: Strange problem with dynamically created control

    Hi,

    I now added .visible = True and hoped that the problem vanished. It seemed so. A dozen customers reported it works fine. But this morning again a customer emailed me the same old problem: text box isn't there!

    It's really annoying! Does anybody know a solution???

    Many thanks in advance

    Physicus.

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: Strange problem with dynamically created control

    Check his resolution. You are hard coding, rather than calculating the screen size first
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Oct 2006
    Posts
    18

    Re: Strange problem with dynamically created control

    @dglienna: This should not be a problem at least for two reasons:

    1.
    It is the same coding as in the xxx.Designer.vb-Files produced by the form-Editor.

    2.
    My coordinates are within 640 x 480 and I am pretty shure my customer works with a higher resolution ;-)

    Best regards,
    Physicus.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center