/// <summary>
        ///     Go to the previous "page"
        /// </summary>
        /// <returns>bool if this worked</returns>
        public bool Previous()
        {
            var result        = false;
            var hasScrollInfo = TryRetrievePosition(out var scrollInfoBefore);

            switch (ScrollMode)
            {
            case ScrollModes.KeyboardPageUpDown:
                result = KeyboardInputGenerator.KeyPresses(VirtualKeyCode.Prior) == 2;
                break;

            case ScrollModes.WindowsMessage:
                result = SendScrollMessage(ScrollBarCommands.SB_PAGEUP);
                break;

            case ScrollModes.AbsoluteWindowMessage:
                if (!hasScrollInfo)
                {
                    return(false);
                }
                // Calculate previous position, clone the scrollInfoBefore
                var scrollInfoForPrevious = scrollInfoBefore;
                scrollInfoForPrevious.Position = Math.Max(scrollInfoBefore.Minimum, scrollInfoBefore.Position - (int)scrollInfoBefore.PageSize);
                result = ApplyPosition(ref scrollInfoForPrevious);
                break;

            case ScrollModes.MouseWheel:
                var bounds      = ScrollingWindow.GetInfo().Bounds;
                var middlePoint = new NativePoint(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
                result = MouseInputGenerator.MoveMouseWheel(WheelDelta, middlePoint) == 1;
                break;
            }
            return(result);
        }
Exemple #2
0
        // retrieve a value by name from a scroll window
        // adapted from James Lyn
        // https://jamesdlyn.wordpress.com/tag/microsoft-dynamics-gp-sdk/
        private DataTable GetScrollWindowValues(ScrollingWindow sender)
        {
            // output
            DataTable dt = new DataTable();

            dt.Columns.Add("Name", typeof(String));
            dt.Columns.Add("Value", typeof(String));

            //Loop through each field
            foreach (var field in sender.Fields)
            {
                string name  = "";
                string value = "";
                try
                {
                    //Loop through the properties of the field looking for Name and Value
                    foreach (var prop in field.GetType().GetProperties())
                    {
                        switch (prop.Name)
                        {
                        case "Name":
                            name = Convert.ToString(prop.GetValue(field, null)).Trim();
                            break;

                        case "Value":
                            value = Convert.ToString(prop.GetValue(field, null)).Trim();
                            break;
                        }
                    }
                }
                catch { }

                //Do not output rows that have blank fields
                if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
                {
                    DataRow row = dt.NewRow();
                    row["Name"]  = name;
                    row["Value"] = value;
                    dt.Rows.Add(row);
                }
            }

            return(dt);
        }