Dynamic Textbox - property setting problem.

Hi

Newbie here, please forgive a simple question.

I have, with the aid of this Community site, made the following code snippet. It works correctly, adds the textbox to my form, with the correct text etc, but, the only property change not working is the Height component which remains at 20 throughout.

From other answers, and the fact that I made my code snippet identical to those, then the Height property should have changed - or, more likely, what am I misunderstanding

cCount += 1

Dim newT As New TextBox

newT.Name = "newT" + cCount.ToString()

newT.Text = "newT test entry : " + cCount.ToString()

newT.Location = New Point(280, 100)

newT.Size = New Size(160, 100)

Controls.Add(newT)




Answer this question

Dynamic Textbox - property setting problem.

  • simdoc

    Thanks again Brendon.

    I had in the meantime experimented with

    newT.Font = New Font("ariel", 32)

    both with and without the

    newT.Multiline = True

    but your suggestion using 'textBox1.Font.Name' is a better solution.



  • Shenry

    OK Brendon, thanks for that.

    It would appear that the posted answer(s) to similar questions were incorrect in as much as they suggested exactly as my snippet showed (indeed, my snippet was produced with those suggestions).

    Can the textbox height also be dynamically controlled by setting a font property for it at run time



  • Kennon2005

    Setting the Font size with something like:

    textBox1.Font = new Font(textBox1.Font.Name, 36)

    On a TextBox where Multiline = false will cause the height of the TextBox to change. If however you change the size when Multiline = true, the size will not change.



  • awoomer

    Add the following line to your snipit:

    newT.Multiline = True

    A TextBox when created is in single line mode and its height is proportional to a single line of text at the specified font size... by changing it to multi-line you are free to change it’s height to your hearts desire.



  • Dynamic Textbox - property setting problem.