PC Review


Reply
Thread Tools Rate Thread

Control scrolling in a TextBox

 
 
Revolvr
Guest
Posts: n/a
 
      18th Sep 2008

I am using a TextBox with a vertical scrollbar as a message area where
messages are accumulated over time as the user does things. Each
message is appended to the previous with a chr(10) in VBA. This keeps
a history of user changes available. Multiline is true.

Problem is, the TextBox seems by default to show the top, or first,
row of information rather than the bottom, most recent information. So
lines are added, but it isn’t visible to the user. Only when I click
in the box it switches to the last line.

What I want is to always be showing the last, most recent line, all
the time, unless the user scrolls up.

Is it possible to create that behavior somehow?

Thanks
 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      18th Sep 2008
Add the new text into the box by appending at the top?

TextBox.Value = "New Message" & vbCrLf & TextBox.Value

instead of

TextBox.Value = TextBox.Value & vbCrLf & "New Message"

--
Regards,
Nigel
(E-Mail Removed)



"Revolvr" <(E-Mail Removed)> wrote in message
news:41c61d11-6f4a-48cf-b5be-(E-Mail Removed)...

I am using a TextBox with a vertical scrollbar as a message area where
messages are accumulated over time as the user does things. Each
message is appended to the previous with a chr(10) in VBA. This keeps
a history of user changes available. Multiline is true.

Problem is, the TextBox seems by default to show the top, or first,
row of information rather than the bottom, most recent information. So
lines are added, but it isn’t visible to the user. Only when I click
in the box it switches to the last line.

What I want is to always be showing the last, most recent line, all
the time, unless the user scrolls up.

Is it possible to create that behavior somehow?

Thanks

 
Reply With Quote
 
Revolvr
Guest
Posts: n/a
 
      18th Sep 2008
On Sep 18, 9:41*am, "Nigel" <nigel-...@nosupanetspam.com> wrote:
> Add the new text into the box by appending at the top?
>
> TextBox.Value = "New Message" & vbCrLf & TextBox.Value
>
> instead of
>
> TextBox.Value = *TextBox.Value & vbCrLf & "New Message"
>
> --
> Regards,
> Nigel
> nigelnos...@9sw.co.uk
>
> "Revolvr" <Revo...@cox.net> wrote in message
>
> news:41c61d11-6f4a-48cf-b5be-(E-Mail Removed)...
>
> I am using a TextBox with a vertical scrollbar as a message area where
> messages are accumulated over time as the user does things. Each
> message is appended to the previous with a chr(10) in VBA. This keeps
> a history of user changes available. Multiline is true.
>
> Problem is, the TextBox seems by default to show the top, or first,
> row of information rather than the bottom, most recent information. So
> lines are added, but it isn’t visible to the user. Only when I click
> in the box it switches to the last line.
>
> What I want is to always be showing the last, most recent line, all
> the time, unless the user scrolls up.
>
> Is it possible to create that behavior somehow?
>
> Thanks



I can try this. But what I am seeing is the scroll bar seems to
position itself neither at the top, nor at the bottom. It seems to
park a few lines from the bottom. Is there direct control over where
it scrolls to?
 
Reply With Quote
 
scattered
Guest
Posts: n/a
 
      18th Sep 2008
On Sep 18, 12:31*pm, Revolvr <Revo...@cox.net> wrote:
> I am using a TextBox with a vertical scrollbar as a message area where
> messages are accumulated over time as the user does things. Each
> message is appended to the previous with a chr(10) in VBA. This keeps
> a history of user changes available. Multiline is true.
>
> Problem is, the TextBox seems by default to show the top, or first,
> row of information rather than the bottom, most recent information. So
> lines are added, but it isn’t visible to the user. Only when I click
> in the box it switches to the last line.
>
> What I want is to always be showing the last, most recent line, all
> the time, unless the user scrolls up.
>
> Is it possible to create that behavior somehow?
>
> Thanks


Maybe the following code snippet will help:

Private Sub btnPress_Click()
Dim s As String
s = InputBox("Enter message")
TextBox1.Text = TextBox1.Text & vbCrLf & s
TextBox1.SetFocus
TextBox1.CurLine = TextBox1.LineCount - 1
btnPress.SetFocus
End Sub


-scattered
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      18th Sep 2008
> > I am using a TextBox with a vertical scrollbar as a message area where
> > messages are accumulated over time as the user does things. Each
> > message is appended to the previous with a chr(10) in VBA. This keeps
> > a history of user changes available. Multiline is true.
> >
> > Problem is, the TextBox seems by default to show the top, or first,
> > row of information rather than the bottom, most recent information. So
> > lines are added, but it isn’t visible to the user. Only when I click
> > in the box it switches to the last line.
> >
> > What I want is to always be showing the last, most recent line, all
> > the time, unless the user scrolls up.
> >
> > Is it possible to create that behavior somehow?
> >
> > Thanks

>
> Maybe the following code snippet will help:
>
> Private Sub btnPress_Click()
> Dim s As String
> s = InputBox("Enter message")
> TextBox1.Text = TextBox1.Text & vbCrLf & s
> TextBox1.SetFocus
> TextBox1.CurLine = TextBox1.LineCount - 1
> btnPress.SetFocus
> End Sub


I would suggest you issue this statement immediately after the CurLine
assignment so the caret (text cursor) is in the more normal position at the
end of the newly added text...

TextBox1.SelStart = Len(TextBox1.Text)

I would also note the this section of the (now modified) code...

.....
.....
TextBox1.SetFocus
TextBox1.CurLine = TextBox1.LineCount - 1
TextBox1.SelStart = Len(TextBox1.Text)
btnPress.SetFocus

could be replaced with this...

.....
.....
TextBox1.SetFocus
SendKeys "^{END}"
btnPress.SetFocus

--
Rick (MVP - Excel)

 
Reply With Quote
 
Revolvr
Guest
Posts: n/a
 
      18th Sep 2008

Thanks for the help so far, but something isn't right.

When I use TextBox1.SelStart = Len(TextBox1.Text)
I get a compile error "Invalid use of property"
I cannot get the LineCount because it says control needs to have focus
first, however, when I use TextBox1.SetFocus I get a run time error
that says "Object doesn't support this property or method".

If it helps, this is Excel 2003.

Any ideas?
 
Reply With Quote
 
scattered
Guest
Posts: n/a
 
      19th Sep 2008
On Sep 18, 6:16*pm, Revolvr <Revo...@cox.net> wrote:
> Thanks for the help so far, but something isn't right.
>
> When I use TextBox1.SelStart = Len(TextBox1.Text)
> I get a compile error "Invalid use of property"
> I cannot get the LineCount because it says control needs to have focus
> first, however, when I use TextBox1.SetFocus I get a run time error
> that says "Object doesn't support this property or method".
>
> If it helps, this is Excel 2003.
>
> Any ideas?


The problem is that embedded text boxes work differently from those on
forms. For the embedded ones, "Activate" evidently plays the role of
SetFocus.

In any event, as an experiment I used the control toolbox to create an
embedded textbox and an embedded button which I renamed btnPress with
the following click event:


Private Sub btnPress_Click()
Dim s As String
s = InputBox("Enter message")
If TextBox1.Text = "" Then
TextBox1.Text = s
Else
TextBox1.Text = TextBox1.Text & vbCrLf & s
End If
TextBox1.Activate
TextBox1.CurLine = TextBox1.LineCount - 1
TextBox1.SelStart = Len(TextBox1.Text)
End Sub

(This incorporates Rick's excellent suggestion which leaves the cursor
at the end of the input - you can activate or select something else
afterwards of course)

This seems to work - just keep hitting button press and adding data.
The bottom row is always visible

hth

-scattered
 
Reply With Quote
 
Revolvr
Guest
Posts: n/a
 
      19th Sep 2008
On Sep 19, 6:43*am, scattered <former_schiz...@hotmail.com> wrote:
> On Sep 18, 6:16*pm, Revolvr <Revo...@cox.net> wrote:
>
> > Thanks for the help so far, but something isn't right.

>
> > When I use TextBox1.SelStart = Len(TextBox1.Text)
> > I get a compile error "Invalid use of property"
> > I cannot get the LineCount because it says control needs to have focus
> > first, however, when I use TextBox1.SetFocus I get a run time error
> > that says "Object doesn't support this property or method".

>
> > If it helps, this is Excel 2003.

>
> > Any ideas?

>
> The problem is that embedded text boxes work differently from those on
> forms. For the embedded ones, "Activate" evidently plays the role of
> SetFocus.
>
> In any event, as an experiment I used the control toolbox to create an
> embedded textbox and an embedded button which I renamed btnPress with
> the following click event:
>
> Private Sub btnPress_Click()
> * * Dim s As String
> * * s = InputBox("Enter message")
> * * If TextBox1.Text = "" Then
> * * * * TextBox1.Text = s
> * * Else
> * * * * TextBox1.Text = TextBox1.Text & vbCrLf & s
> * * End If
> * * TextBox1.Activate
> * * TextBox1.CurLine = TextBox1.LineCount - 1
> * * TextBox1.SelStart = Len(TextBox1.Text)
> End Sub
>
> (This incorporates Rick's excellent suggestion which leaves the cursor
> at the end of the input - you can activate or select something else
> afterwards of course)
>
> This seems to work - just keep hitting button press and adding data.
> The bottom row is always visible
>
> hth
>
> -scattered



That's it! Of course, Instead of using SetFocus to set focus, use
Activate, if it's an embedded text box. I would not have guessed. That
solved it. Thanks.
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrolling problem with ListView, TextBox and Scrolling Panel Jon Abaunza Microsoft Dot NET Compact Framework 0 17th Nov 2005 03:57 PM
How to use reflection on textbox control to allow program control of scrolling? notu Microsoft Dot NET Compact Framework 3 7th Jul 2005 07:03 AM
Dynamic Control of Scrolling TextBox =?Utf-8?B?ZGJfZnJvbV9tbg==?= Microsoft Dot NET 2 3rd Jun 2005 01:36 PM
Textbox scrolling ray well Microsoft C# .NET 4 12th Aug 2003 09:45 PM
Re: VERY STRANGE BUG? Adding a textbox control causes other textbox control to fail??? S. Justin Gengo Microsoft ASP .NET 0 16th Jul 2003 07:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:51 AM.