[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

License Agreement Textbox Scroll-To-End Event?

Posted on 2006-05-30
9
Medium Priority
?
732 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:kvnsdr
9 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16794296
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
 
LVL 5

Expert Comment

by:aaronfeng
ID: 16794483
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
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 16794623
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16795336
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
 
LVL 1

Author Comment

by:kvnsdr
ID: 16797612
Yes, that would be nice....  Thank You.....
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16799728
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
 
LVL 1

Author Comment

by:kvnsdr
ID: 16807056
Thanks again........
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16807095
Did it work?  Not work?

Better than using keystrokes alone?

Any questions?...
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 16808502
It works, thanks again...........
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question