PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET Dynamically created TextBox: Caret can be placed in middle of theblank area!

Reply

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

 
Thread Tools Rate Thread
Old 22-05-2008, 04:43 PM   #1
Jeannot
Guest
 
Posts: n/a
Default Dynamically created TextBox: Caret can be placed in middle of theblank area!


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)


  Reply With Quote
Old 23-05-2008, 01:44 PM   #2
Jeannot
Guest
 
Posts: n/a
Default Re: Dynamically created TextBox: Caret can be placed in middle of theblank area!

On May 22, 9:24 pm, "Steve Gerrard" <mynameh...@comcast.net> wrote:
> Jeannot wrote:
> > 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.

  Reply With Quote
Old 23-05-2008, 09:05 PM   #3
Jeannot
Guest
 
Posts: n/a
Default Re: Dynamically created TextBox: Caret can be placed in middle of theblank area!

On May 23, 10:09 am, "Steve Gerrard" <mynameh...@comcast.net> wrote:
> Jeannot wrote:
>
> >> 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 ?

>
> 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.


  Reply With Quote
Old 30-06-2008, 05:25 PM   #4
vlad
Guest
 
Posts: n/a
Default Re: Dynamically created TextBox: Caret can be placed in middle of


"Jeannot" wrote:

> 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

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off