License Agreement Textbox Scroll-To-End Event?

I like the idea of several End User License Agreement textboxes that allow a checkbox.Enabled = true only when the scrollbars are moved completely up, showing all the text.

Q. Is there a Scrollbar event?
LVL 1
kvnsdrAsked:
Who is Participating?
 
Daniel Van Der WerkenIndependent ConsultantCommented:
I would use Platform Invoke on SendMessage and put it in the event handler for down-arrow in the text box.  Then, if it returns FALSE, you can't scroll down anymore and make the checkbox enabled.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_getline.asp

Here's mine for an example, but I used it to make the text go to the end of the textbox (which is another option for you).

            [DllImport("User32.Dll")]
            private static extern Int32 SendMessage(IntPtr hWnd, Int32 msg,
                  Int32 wParam, Int32 lParam);
            public const int EM_LINESCROLL = 0x00B6;
                  
int iRet = SendMessage(debugText.Handle, EM_LINESCROLL, 0, (_lineNumber-25));
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You have to subclass and watch for the WM_VSCROLL msg.  Then you can use the GetScrollInfo() API to determine where the scrollbars are at and act accordingly...

Here is one way to do it in VB.Net:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_21798916.html
0
 
aaronfengCommented:
Nope, there isn't a scrollbar event for textbox.  There is a scrolling event called VScroll on richtextbox, but it won't help you because it doesn't tell you the scrollbar location, the event is called when you click on the scrollbar.  The only way to figure out the scrolling position is to override WndProc for either of the controls.  I think this might be too much work to do what you wanted to do (maybe not).  You can have another checkbox that says "Check here if you read everything" then you can enable the control you want.  This would be pretty easy to do.

Cheers,

Aaron
http://aaronfeng.blogspot.com/
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
And what if the user scrolls to the bottom using the mouse alone?

I can post a C# version of the VB.net code I referenced if you like...
0
 
kvnsdrAuthor Commented:
Yes, that would be nice....  Thank You.....
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Usage:

            EulaForm ef = new EulaForm();
            if (ef.ShowDialog() == DialogResult.OK)
            {
                System.Diagnostics.Debug.WriteLine("EULA Accepted");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("EULA Rejected");
            }



And here is my EulaForm:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
    public partial class EulaForm : Form
    {
        public EulaForm()
        {
            InitializeComponent();
        }

        private MyTextBox mtb;

        private void EulaForm_Load(object sender, EventArgs e)
        {
            AgreeCheckBox.Enabled = false;
            AcceptEulaButton.Enabled = false;

            mtb = new MyTextBox(textBox1);
            mtb.BottomReached += new MyTextBox.ScrolledToBottom(mtb_BottomReached);
        }

        void mtb_BottomReached()
        {
            AgreeCheckBox.Enabled = true;
        }

        private void AgreeCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            AcceptEulaButton.Enabled = AgreeCheckBox.Checked;
        }

        private void AcceptEulaButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void RejectEulaButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private class MyTextBox : NativeWindow
        {
            private const Int32 SB_VERT = 0x1;
            private const Int32 SIF_PAGE = 0x2;
            private const Int32 SIF_POS = 0x4;
            private const Int32 SIF_RANGE = 0x1;
            private const Int32 SIF_TRACKPOS = 0x10;
            private const Int32 SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS);
            private const Int32 WM_VSCROLL = 0x115;
            private const Int32 WM_KEYDOWN = 0x0100;
            private const Int32 WM_MOUSEWHEEL = 0x020A;

            public struct SCROLLINFO
            {
                public Int32 cbSize;
                public Int32 fMask;
                public Int32 nMin;
                public Int32 nMax;
                public Int32 nPage;
                public Int32 nPos;
                public Int32 nTrackPos;
            }

            [DllImport("User32.dll", EntryPoint = "GetScrollInfo")]
            public static extern bool GetScrollInfo([In]IntPtr hwnd, [In]int fnBar, [In, Out]ref SCROLLINFO lpsi);

            public delegate void ScrolledToBottom();
            public event ScrolledToBottom BottomReached;

            public MyTextBox(TextBox tb)
            {
                if (tb != null)
                {
                    this.AssignHandle(tb.Handle);
                }
            }

            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case WM_KEYDOWN :
                    case WM_MOUSEWHEEL :
                    case WM_VSCROLL :
                        SCROLLINFO typSI = new SCROLLINFO();
                        typSI.cbSize = Marshal.SizeOf(typSI);
                        typSI.fMask = SIF_ALL;
                        GetScrollInfo(this.Handle, SB_VERT, ref typSI);
                        if (typSI.nPos >= (typSI.nMax - typSI.nPage))
                        {
                            BottomReached();
                        }
                        break;

                }

                base.WndProc(ref m);
            }

        }

    }
}
0
 
kvnsdrAuthor Commented:
Thanks again........
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Did it work?  Not work?

Better than using keystrokes alone?

Any questions?...
0
 
kvnsdrAuthor Commented:
It works, thanks again...........
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.