Dynamically created TextBox: Caret can be placed in middle of theblank area!

  • Thread starter Thread starter Jeannot
  • Start date Start date
J

Jeannot

VS2008, VB, .NET 3.5
When I create a TextBox in Designer, then at runtime wherever I click,
the caret is placed at the end of the text the box actually contains.
But when I create a TextBox dynamically, the caret stays wherever I
clicked, int he middle of nowhere.

Is this a property that defaults different in Designer or at runtime,
or is it a bug?

My code:

Dim tb As System.Windows.Forms.TextBox = New
System.Windows.Forms.TextBox
tb.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or
AnchorStyles.Top
tb.Multiline = True
tb.Height = 100
tb.Text = "Yo Man"
panelDocument.Controls.Add(tb)
 
It doesn't happen that way at all on my machine. I pasted this code, assuming
panelDocument is a Panel control. Works fine, produces a perfectly normal
TextBox, caret behaves as you described for the designer version.

What else are you doing? Somewhere else in your code lies the answer...

You are correct that the parent is a Panel.
tb is not referred to anywhere outside of the code you see, except for
setting Top-Left-Width
You are on VS2008, VB, .NET 3.5 ?

I'll try "Name"ing it, and swapping the order in which I set the
properties.
 
Actually I'm on VS2005, VB, .NET 2.0. Can't believe that would make a
difference, though.

It's a mystery. Are you testing this is a small app by itself? It might be worth
it, to help isolate the issue.

Okay, problem solved. Thanks for your help Steve.
My problem was self-inflicted during a senior moment.

It is very unlikely that others will see the same problem, so
humiliating myself by describing it would not help anyone.
 
Jeannot said:
Okay, problem solved. Thanks for your help Steve.
My problem was self-inflicted during a senior moment.

It is very unlikely that others will see the same problem, so
humiliating myself by describing it would not help anyone.

maybe unlikely, but not impossible. in fact, i have the exact same problem
but i have absolutely no clue how to turn off this feature.

so it would be great if you could please share your solution here.

regards,
vlad
 
Back
Top