By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,087 Members | 1,513 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,087 IT Pros & Developers. It's quick & easy.

Form auto scrolling issue

P: n/a
23s
Is there any way I can send a vertical value to a form's scroll position?

I have a full-screen form that, at launch, contains an empty tab sheet.

At run time, the user can dynamically append a rich textbox to the tab
sheet. The rich textbox is placed at 0,0 (upper left corner) within the tab
sheet and is initially 1 "line" tall to accomodate the user's first line of
text.

The rich text box is, in actuality, a user control of mine that resizes
itself to always "fit" whatever the user has typed into it, so that all text
they have typed is visible at all times, without inducing scrollbars on the
rich textbox (while maintaining the minimum possible vertical size). In
essence, the rich textbox height is consistantly equivalent to "number of
lines * however tall your font is" (although that's not the exact equation,
that's the net visual result).

A routine exists that resizes the tab sheet in a similar fashion; to "fit"
perfectly around the rich textbox. Every time the rich textbox decides it
needs to resize because the number of lines has changed, it fires the
routine on the form that resizes the tab sheet to fit perfectly around the
rich textbox (vertically).

So in virtual tandum, my rich textbox and my tabsheet resize themselves in
reaction to however many lines are in the rich textbox, in real time as the
user types.

I need to maintain visibility of the .SelectionStart position of the rich
textbox at all times. Which is a true condition by default, until the user
has typed quite a bit of stuff, and produced more lines than fit on the
maximized form at the current screen resolution. At that point, the rich
textbox is quite tall, the tab sheet is now quite tall, and the vertical
auto-scrolling of the form kicks in to accomodate the tall tab sheet. And
this is desireable behavior. However, the form will curiously not
auto-scroll beyond the "top" of the rich textbox; and consequently, I can
type and type further and further down "off the screen"; my rich textbox is
resizing correctly, the tab sheet is resizing correctly, but because the
form is suddenly stubborn in how far down it will scroll, the
..SelectionStart is no longer visible to the user. But .SelectionStart must
remain visible, and (I assume) that means I must programmatically scroll the
form downwards. No problem, or so I thought. After the "resize the tab
sheet" operation, I need to check to see if I need to "scroll the form down,
to keep .SelectionStart in view" but I can't figure out how to accomplish
that yet.

I tried the .ScrollToCaret method of the rich textbox itself, however within
the context of the rich textbox, there are no scroll bars, ergo nowhere to
scroll. As far as it's concerned, it's already scrolled to everywhere. The
problem is with the scrollbars on the form, and not the rich textbox.

Next I tried the .AutoScrollPosition of the form, but that doesn't seem to
be remedying the problem either - it also seems obliged to stop scrolling as
soon as the top of the rich textbox reaches vertical position 0 on the form,
and the scrolling halts there. I can manuall scroll it with the scroll bars
at runtime, but I need to do this programmatically.

Is there any way I can manually override this behavior and force the form,
programmatically, to scroll down beyond the top of the rich textbox? Why is
it stopping at the top of the rich textbox and how can I programmatically
scroll beyond it?
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.