1

I am trying to create a form with a multi-line TextBox with the following requirements:

  • The text in the text box might be short or long.
  • There is not much space availble.
  • I want to be sure that the entirety of the text has been seen. I can't be sure that the user has actually read it, but I can at least require that all of it has been seen.

So I'm trying to make a "fully viewed" multi-line TextBox.

This picture should make it clear what I'm trying to do:

enter image description here

If they check the checkbox before they've scrolled through the whole thing, I'll know not to believe them.

I think I need to know:

  • When the form comes up, was the text that was put into the TextBox short (all visible without scrolling) or long (the vertical scroll bar was shown)?
  • If the vertical scroll bar is showing, has the user scrolled it all the way to the bottom?

Any ideas about how to achieve this?

Jeff Roe
  • 3,147
  • 32
  • 45

1 Answers1

2

The TextBox has no scrolling event but the RichTextBox has. Also it has a method that allows you to get the index of the character closest to a point position.

private readonly Point _lowerRightCorner;

public frmDetectTextBoxScroll()
{
    InitializeComponent();
    _lowerRightCorner = new Point(richTextBox1.ClientRectangle.Right,
                                  richTextBox1.ClientRectangle.Bottom);
}

private void richTextBox1_VScroll(object sender, EventArgs e)
{
    int index = richTextBox1.GetCharIndexFromPosition(_lowerRightCorner);
    if (index == richTextBox1.TextLength - 1) {
        // Enable your checkbox here
    }
}
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188