private void TestForm_Load(object sender, EventArgs e)
        {
            propertyGrid.SelectedObject = domainUpDown;

            GridEntryCollection entries          = propertyGrid.GetPropEntries();
            PropertyGridView    propertyGridView = (PropertyGridView)propertyGrid.ActiveControl;

            foreach (GridEntry entry in entries)
            {
                int entryHeight = propertyGridView.AccessibilityGetGridEntryBounds(entry).Height;
                AccRowHeightSum += entryHeight;
                if (entryHeight > 0)
                {
                    entriesBorders++;
                }

                foreach (GridEntry item in entry.GridItems)
                {
                    int itemHeight = propertyGridView.AccessibilityGetGridEntryBounds(item).Height;
                    AccRowHeightSum += itemHeight;
                    if (itemHeight > 0)
                    {
                        entriesBorders++;
                    }
                }
            }
            AccPropertyGridViewHeight = propertyGridView.AccessibilityObject.Bounds.Height;

            Application.Exit();
        }
        public void PropertyGridViewAccessibleObject_GetItem_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            propertyGrid.CreateControl();
            using ComboBox comboBox     = new ComboBox();
            propertyGrid.SelectedObject = comboBox;
            AccessibleObject accessibleObject = propertyGrid.GridViewAccessibleObject;

            int i = 0;

            foreach (GridEntry category in propertyGrid.GetPropEntries())
            {
                AccessibleObject categoryAccessibilityObject = category.AccessibilityObject;
                AccessibleObject categoryItem = (AccessibleObject)accessibleObject.GetItem(i, 1);
                Assert.Equal(categoryAccessibilityObject, categoryItem);
                i++;

                foreach (GridEntry entry in category.Children)
                {
                    AccessibleObject entryAccessibilityObject = entry.AccessibilityObject;
                    AccessibleObject entryItem = (AccessibleObject)accessibleObject.GetItem(i, 1);
                    Assert.Equal(categoryAccessibilityObject, categoryItem);
                    i++;
                }
            }
        }
        public void PropertyGridViewAccessibleObject_GetSelected_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            using ComboBox comboBox         = new ComboBox();
            propertyGrid.SelectedObject     = comboBox;
            GridEntry entry = (GridEntry)((GridEntry)propertyGrid.GetPropEntries()[0]).Children[2];

            entry.Focus = true;
            entry.Select();
            Assert.Equal(entry, propertyGrid.SelectedGridItem);

            AccessibleObject focusedEntry = propertyGrid.GridViewAccessibleObject.GetSelected();

            Assert.Equal(entry.AccessibilityObject, focusedEntry);
        }
        public void PropertyGridViewAccessibleObject_Entry_IsOffscreen_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            propertyGrid.Size     = new Size(300, 500);
            propertyGrid.Location = new Point(0, 0);
            propertyGrid.CreateControl();
            using ComboBox comboBox     = new ComboBox();
            propertyGrid.SelectedObject = comboBox;
            ControlAccessibleObject accessibleObject = (ControlAccessibleObject)propertyGrid.GridViewAccessibleObject;
            PropertyGridView        propertyGridView = (PropertyGridView)accessibleObject.Owner;

            Rectangle gridViewRectangle = accessibleObject.Bounds;

            int ROWLABEL = 1;
            int ROWVALUE = 2;

            foreach (GridEntry category in propertyGrid.GetPropEntries())
            {
                AccessibleObject categoryAccessibilityObject = category.AccessibilityObject;
                int       row  = propertyGridView.GetRowFromGridEntry(category);
                Rectangle rect = propertyGridView.GetRectangle(row, ROWVALUE | ROWLABEL);
                rect = propertyGridView.RectangleToScreen(rect);

                bool visible = rect.Height > 0 &&
                               ((rect.Y > gridViewRectangle.Y + 1 && rect.Y < gridViewRectangle.Bottom - 1) ||
                                (rect.Y <gridViewRectangle.Bottom - 1 && rect.Bottom> gridViewRectangle.Y + 1)); // +-1 are borders

                Assert.Equal(!visible, (bool)categoryAccessibilityObject.GetPropertyValue(UiaCore.UIA.IsOffscreenPropertyId));

                foreach (GridEntry entry in category.Children)
                {
                    AccessibleObject entryAccessibilityObject = entry.AccessibilityObject;
                    row  = propertyGridView.GetRowFromGridEntry(entry);
                    rect = propertyGridView.GetRectangle(row, ROWVALUE | ROWLABEL);
                    rect = propertyGridView.RectangleToScreen(rect);

                    visible = rect.Height > 0 &&
                              ((rect.Y > gridViewRectangle.Y + 1 && rect.Y < gridViewRectangle.Bottom - 1) ||
                               (rect.Y <gridViewRectangle.Bottom - 1 && rect.Bottom> gridViewRectangle.Y + 1));  // +-1 are borders

                    Assert.Equal(!visible, (bool)entryAccessibilityObject.GetPropertyValue(UiaCore.UIA.IsOffscreenPropertyId));
                }
            }
        }
        public void PropertyGridViewAccessibleObject_GetChildCount_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            AccessibleObject accessibleObject = propertyGrid.GridViewAccessibleObject;

            Assert.Equal(0, accessibleObject.GetChildCount()); // propertyGrid doesn't have an item

            using ComboBox comboBox     = new ComboBox();
            propertyGrid.SelectedObject = comboBox;

            int count = 0;

            foreach (GridEntry category in propertyGrid.GetPropEntries())
            {
                count++;

                foreach (GridEntry entry in category.Children)
                {
                    count++;
                }
            }

            Assert.Equal(count, accessibleObject.GetChildCount()); // Properties
        }
        public ScenarioResult PropertyGridViewRowsAccessibleObject_Ctor_Default(TParams p)
        {
            _propertyGrid.SelectedObject = _domainUpDown;
            int heightSum      = 0;
            int entriesBorders = 0;

            GridEntryCollection entries          = _propertyGrid.GetPropEntries();
            PropertyGridView    propertyGridView = (PropertyGridView)_propertyGrid.ActiveControl;

            foreach (GridEntry entry in entries)
            {
                int entryHeight = propertyGridView.AccessibilityGetGridEntryBounds(entry).Height;
                heightSum += entryHeight;
                if (entryHeight > 0)
                {
                    entriesBorders++;
                }

                foreach (GridEntry item in entry.GridItems)
                {
                    int itemHeight = propertyGridView.AccessibilityGetGridEntryBounds(item).Height;
                    heightSum += itemHeight;
                    if (itemHeight > 0)
                    {
                        entriesBorders++;
                    }
                }
            }

            if (heightSum != propertyGridView.AccessibilityObject.Bounds.Height - topBorder - bottomBorder - entriesBorders)
            {
                return(new ScenarioResult(false, "Incorrect dimensions"));
            }

            return(new ScenarioResult(true));
        }