Example #1
0
 private ArrayList FindInternal(string key, bool searchAllChildren, TreeNodeCollection treeNodeCollectionToLookIn, ArrayList foundTreeNodes)
 {
     if ((treeNodeCollectionToLookIn == null) || (foundTreeNodes == null))
     {
         return(null);
     }
     for (int i = 0; i < treeNodeCollectionToLookIn.Count; i++)
     {
         if ((treeNodeCollectionToLookIn[i] != null) && WindowsFormsUtils.SafeCompareStrings(treeNodeCollectionToLookIn[i].Name, key, true))
         {
             foundTreeNodes.Add(treeNodeCollectionToLookIn[i]);
         }
     }
     if (searchAllChildren)
     {
         for (int j = 0; j < treeNodeCollectionToLookIn.Count; j++)
         {
             if (((treeNodeCollectionToLookIn[j] != null) && (treeNodeCollectionToLookIn[j].Nodes != null)) && (treeNodeCollectionToLookIn[j].Nodes.Count > 0))
             {
                 foundTreeNodes = this.FindInternal(key, searchAllChildren, treeNodeCollectionToLookIn[j].Nodes, foundTreeNodes);
             }
         }
     }
     return(foundTreeNodes);
 }
 public override int GetHashCode()
 {
     // Structs should implement GetHashCode for perf
     return(WindowsFormsUtils.GetCombinedHashCodes(
                this.row,
                this.column));
 }
Example #3
0
 public override int GetHashCode()
 {
     return(Left
            ^ WindowsFormsUtils.RotateLeft(Top, 8)
            ^ WindowsFormsUtils.RotateLeft(Right, 16)
            ^ WindowsFormsUtils.RotateLeft(Bottom, 24));
 }
 private void FindInternal(string key, bool searchAllSubItems, ListViewItemCollection listViewItems, List <ListViewItem> foundItems)
 {
     for (int i = 0; i < listViewItems.Count; i++)
     {
         if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].Name, key, ignoreCase: true))
         {
             foundItems.Add(listViewItems[i]);
         }
         else
         {
             if (searchAllSubItems)
             {
                 // start from 1, as we've already compared subitems[0]
                 for (int j = 1; j < listViewItems[i].SubItems.Count; j++)
                 {
                     if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].SubItems[j].Name, key, ignoreCase: true))
                     {
                         foundItems.Add(listViewItems[i]);
                         break;
                     }
                 }
             }
         }
     }
 }
            public virtual int IndexOfKey(string key)
            {
                // Step 0 - Arg validation
                if (string.IsNullOrEmpty(key))
                {
                    return(-1); // we dont support empty or null keys.
                }

                // step 1 - check the last cached item
                if (IsValidIndex(lastAccessedIndex))
                {
                    if (WindowsFormsUtils.SafeCompareStrings(this[lastAccessedIndex].Name, key, /* ignoreCase = */ true))
                    {
                        return(lastAccessedIndex);
                    }
                }

                // step 2 - search for the item
                for (int i = 0; i < Count; i++)
                {
                    if (WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, /* ignoreCase = */ true))
                    {
                        lastAccessedIndex = i;
                        return(i);
                    }
                }

                // step 3 - we didn't find it.  Invalidate the last accessed index and return -1.
                lastAccessedIndex = -1;
                return(-1);
            }
Example #6
0
            private ArrayList FindInternal(string key, bool searchAllSubItems, ListViewItemCollection listViewItems, ArrayList foundItems)
            {
                if ((listViewItems is null) || (foundItems is null))
                {
                    return(null);  //
                }

                for (int i = 0; i < listViewItems.Count; i++)
                {
                    if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].Name, key, /* ignoreCase = */ true))
                    {
                        foundItems.Add(listViewItems[i]);
                    }
                    else
                    {
                        if (searchAllSubItems)
                        {
                            // start from 1, as we've already compared subitems[0]
                            for (int j = 1; j < listViewItems[i].SubItems.Count; j++)
                            {
                                if (WindowsFormsUtils.SafeCompareStrings(listViewItems[i].SubItems[j].Name, key, /* ignoreCase = */ true))
                                {
                                    foundItems.Add(listViewItems[i]);
                                    break;
                                }
                            }
                        }
                    }
                }

                return(foundItems);
            }
Example #7
0
            public virtual int IndexOfKey(string key)
            {
                if (string.IsNullOrEmpty(key))
                {
                    return(-1);
                }

                if (IsValidIndex(lastAccessedIndex))
                {
                    if (WindowsFormsUtils.SafeCompareStrings(this[lastAccessedIndex].Name, key, true))
                    {
                        return(lastAccessedIndex);
                    }
                }

                for (int i = 0; i < Count; i++)
                {
                    if (!WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, true))
                    {
                        continue;
                    }

                    lastAccessedIndex = i;
                    return(i);
                }

                lastAccessedIndex = -1;
                return(-1);
            }
Example #8
0
        internal override Size GetPreferredSizeCore(Size proposedConstraints)
        {
            Size textExtent;
            Size bordersAndPadding = this.GetBordersAndPadding();

            proposedConstraints -= bordersAndPadding;
            proposedConstraints  = LayoutUtils.UnionSizes(proposedConstraints, Size.Empty);
            if (string.IsNullOrEmpty(this.Text))
            {
                using (WindowsFont font = WindowsFont.FromFont(this.Font))
                {
                    textExtent       = WindowsGraphicsCacheManager.MeasurementGraphics.GetTextExtent("0", font);
                    textExtent.Width = 0;
                    goto Label_0113;
                }
            }
            if (this.UseGDIMeasuring())
            {
                TextFormatFlags flags = (this.FlatStyle == System.Windows.Forms.FlatStyle.System) ? TextFormatFlags.Default : this.CreateTextFormatFlags(proposedConstraints);
                textExtent = this.MeasureTextCache.GetTextSize(this.Text, this.Font, proposedConstraints, flags);
            }
            else
            {
                using (Graphics graphics = WindowsFormsUtils.CreateMeasurementGraphics())
                {
                    using (StringFormat format = this.CreateStringFormat())
                    {
                        SizeF layoutArea = (proposedConstraints.Width == 1) ? new SizeF(0f, (float)proposedConstraints.Height) : new SizeF((float)proposedConstraints.Width, (float)proposedConstraints.Height);
                        textExtent = Size.Ceiling(graphics.MeasureString(this.Text, this.Font, layoutArea, format));
                    }
                }
            }
Label_0113:
            return(textExtent + bordersAndPadding);
        }
Example #9
0
            /// <devdoc> ApplySettings - applies settings from the stub into a full-fledged
            ///          TableLayoutSettings.
            ///
            ///          NOTE: this is a one-time only operation - there is data loss to the stub
            ///          as a result of calling this function. we hand as much over to the other guy
            ///          so we dont have to reallocate anything
            /// </devdoc>
            internal void ApplySettings(TableLayoutSettings settings)
            {
                //
                // apply row,column,rowspan,colspan
                //
                TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(settings.Owner);
                Control appliedControl = containerInfo.Container as Control;

                if (appliedControl != null && controlsInfo != null)
                {
                    // we store the control names, look up the controls
                    // in the appliedControl's control collection and apply the row,column settings.
                    foreach (object controlName in controlsInfo.Keys)
                    {
                        ControlInformation controlInfo = controlsInfo[controlName];

                        // Look for the control in our table, we have to go through
                        // PropertyDescriptor rather than just going using appliedControl.Controls[controlName]
                        // because the Name property is shadowed at design time
                        foreach (Control tableControl in appliedControl.Controls)
                        {
                            if (tableControl != null)
                            {
                                string             name = null;
                                PropertyDescriptor prop = TypeDescriptor.GetProperties(tableControl)["Name"];
                                if (prop != null && prop.PropertyType == typeof(string))
                                {
                                    name = prop.GetValue(tableControl) as string;
                                }
                                else
                                {
                                    Debug.Fail("Name property missing on control");
                                }
                                if (WindowsFormsUtils.SafeCompareStrings(name, controlName as string, /* ignoreCase = */ false))
                                {
                                    settings.SetRow(tableControl, controlInfo.Row);
                                    settings.SetColumn(tableControl, controlInfo.Column);
                                    settings.SetRowSpan(tableControl, controlInfo.RowSpan);
                                    settings.SetColumnSpan(tableControl, controlInfo.ColumnSpan);
                                    break;
                                }
                            }
                        }
                    }
                }

                //
                // assign over the row and column styles
                //
                containerInfo.RowStyles    = rowStyles;
                containerInfo.ColumnStyles = columnStyles;

                // since we've given over the styles to the other guy, null out.
                columnStyles = null;
                rowStyles    = null;

                // set a flag for assertion detection.
                isValid = false;
            }
Example #10
0
 /// <include file='doc\Padding.uex' path='docs/doc[@for="Padding.GetHashCode"]/*' />
 public override int GetHashCode()
 {
     // Padding class should implement GetHashCode for perf
     return(Left
            ^ WindowsFormsUtils.RotateLeft(Top, 8)
            ^ WindowsFormsUtils.RotateLeft(Right, 16)
            ^ WindowsFormsUtils.RotateLeft(Bottom, 24));
 }
Example #11
0
 protected override bool ProcessCmdKey(ref Message m, Keys keyData)
 {
     if ((!ToolStripManager.ModalMenuFilter.InMenuMode || (keyData != Keys.Space)) || (!this.Focused && base.ContainsFocus))
     {
         return(base.ProcessCmdKey(ref m, keyData));
     }
     base.NotifySelectionChange(null);
     ToolStripManager.ModalMenuFilter.ExitMenuMode();
     System.Windows.Forms.UnsafeNativeMethods.PostMessage(WindowsFormsUtils.GetRootHWnd(this), 0x112, 0xf100, 0x20);
     return(true);
 }
Example #12
0
        /// <devdoc>
        ///     <para>Searches for Items by their Name property, builds up an array list
        ///           of all the items that match.
        ///     </para>
        /// </devdoc>
        /// <internalonly/>
        private ArrayList FindInternal(string key, bool searchAllChildren, ToolStripItemCollection itemsToLookIn, ArrayList foundItems)
        {
            if ((itemsToLookIn == null) || (foundItems == null))
            {
                return(null);  //
            }

            try
            {
                for (int i = 0; i < itemsToLookIn.Count; i++)
                {
                    if (itemsToLookIn[i] == null)
                    {
                        continue;
                    }

                    if (WindowsFormsUtils.SafeCompareStrings(itemsToLookIn[i].Name, key, /* ignoreCase = */ true))
                    {
                        foundItems.Add(itemsToLookIn[i]);
                    }
                }


                // Optional recurive search for controls in child collections.

                if (searchAllChildren)
                {
                    for (int j = 0; j < itemsToLookIn.Count; j++)
                    {
                        ToolStripDropDownItem item = itemsToLookIn[j] as ToolStripDropDownItem;
                        if (item == null)
                        {
                            continue;
                        }
                        if (item.HasDropDownItems)
                        {
                            // if it has a valid child collecion, append those results to our collection
                            foundItems = FindInternal(key, searchAllChildren, item.DropDownItems, foundItems);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Make sure we deal with non-critical failures gracefully.
                if (ClientUtils.IsCriticalException(e))
                {
                    throw;
                }
            }

            return(foundItems);
        }
Example #13
0
        protected override void  WndProc(ref Message m)
        {
            if ((m.Msg == NativeMethods.WM_NCHITTEST) && SizingGrip)
            {
                // if we're within the grip bounds tell windows
                // that we're the bottom right of the window.
                Rectangle sizeGripBounds = SizeGripBounds;
                int       x = NativeMethods.Util.LOWORD(m.LParam);
                int       y = NativeMethods.Util.HIWORD(m.LParam);


                if (sizeGripBounds.Contains(PointToClient(new Point(x, y))))
                {
                    HandleRef rootHwnd = WindowsFormsUtils.GetRootHWnd(this);

                    // if the main window isnt maximized - we should paint a resize grip.
                    // double check that we're at the bottom right hand corner of the window.
                    if (rootHwnd.Handle != IntPtr.Zero && !UnsafeNativeMethods.IsZoomed(rootHwnd))
                    {
                        // get the client area of the topmost window.  If we're next to the edge then
                        // the sizing grip is valid.
                        NativeMethods.RECT rootHwndClientArea = new NativeMethods.RECT();
                        UnsafeNativeMethods.GetClientRect(rootHwnd, ref rootHwndClientArea);

                        // map the size grip FROM statusStrip coords TO the toplevel window coords.
                        NativeMethods.POINT gripLocation;
                        if (RightToLeft == RightToLeft.Yes)
                        {
                            gripLocation = new NativeMethods.POINT(SizeGripBounds.Left, SizeGripBounds.Bottom);
                        }
                        else
                        {
                            gripLocation = new NativeMethods.POINT(SizeGripBounds.Right, SizeGripBounds.Bottom);
                        }
                        UnsafeNativeMethods.MapWindowPoints(new HandleRef(this, this.Handle), rootHwnd, gripLocation, 1);

                        int deltaBottomEdge = Math.Abs(rootHwndClientArea.bottom - gripLocation.y);
                        int deltaRightEdge  = Math.Abs(rootHwndClientArea.right - gripLocation.x);

                        if (RightToLeft != RightToLeft.Yes)
                        {
                            if ((deltaRightEdge + deltaBottomEdge) < 2)
                            {
                                m.Result = (IntPtr)NativeMethods.HTBOTTOMRIGHT;
                                return;
                            }
                        }
                    }
                }
            }
            base.WndProc(ref m);
        }
 /// <include file='doc\DataGridViewCellStyle.uex' path='docs/doc[@for="DataGridViewCellStyle.GetHashCode"]/*' />
 public override int GetHashCode()
 {
     return(WindowsFormsUtils.GetCombinedHashCodes((int)this.Alignment,
                                                   (int)this.WrapMode,
                                                   this.Padding.GetHashCode(),
                                                   this.Format.GetHashCode(),
                                                   this.BackColor.GetHashCode(),
                                                   this.ForeColor.GetHashCode(),
                                                   this.SelectionBackColor.GetHashCode(),
                                                   this.SelectionForeColor.GetHashCode(),
                                                   (this.Font == null ? 1 : this.Font.GetHashCode()),
                                                   (this.NullValue == null ? 1 : this.NullValue.GetHashCode()),
                                                   (this.DataSourceNullValue == null ? 1 : this.DataSourceNullValue.GetHashCode()),
                                                   (this.Tag == null ? 1 : this.Tag.GetHashCode())));
 }
Example #15
0
            /// <summary>
            ///  Searches for Controls by their Name property, builds up an array list
            ///  of all the controls that match.
            /// </summary>
            private ArrayList FindInternal(string key, bool searchAllChildren, ControlCollection controlsToLookIn, ArrayList foundControls)
            {
                if ((controlsToLookIn == null) || (foundControls == null))
                {
                    return(null);
                }

                try
                {
                    // Perform breadth first search - as it's likely people will want controls belonging
                    // to the same parent close to each other.
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] == null)
                        {
                            continue;
                        }

                        if (WindowsFormsUtils.SafeCompareStrings(controlsToLookIn[i].Name, key, /* ignoreCase = */ true))
                        {
                            foundControls.Add(controlsToLookIn[i]);
                        }
                    }

                    // Optional recurive search for controls in child collections.

                    if (searchAllChildren)
                    {
                        for (int i = 0; i < controlsToLookIn.Count; i++)
                        {
                            if (controlsToLookIn[i] == null)
                            {
                                continue;
                            }
                            if ((controlsToLookIn[i].Controls != null) && controlsToLookIn[i].Controls.Count > 0)
                            {
                                // if it has a valid child collecion, append those results to our collection
                                foundControls = FindInternal(key, searchAllChildren, controlsToLookIn[i].Controls, foundControls);
                            }
                        }
                    }
                }
                catch (Exception e) when(!ClientUtils.IsSecurityOrCriticalException(e))
                {
                }
                return(foundControls);
            }
        public virtual int IndexOfKey(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(-1);
            }

            for (int i = 0; i < Count; i++)
            {
                if (WindowsFormsUtils.SafeCompareStrings(items[i].Name, key, true))
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #17
0
        internal void ShowInTaskbar(int x, int y)
        {
            base.WorkingAreaConstrained = false;
            Rectangle rect   = base.CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveLeft);
            Rectangle bounds = Screen.FromRectangle(rect).Bounds;

            if (rect.Y < bounds.Y)
            {
                rect = base.CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.BelowLeft);
            }
            else if (rect.X < bounds.X)
            {
                rect = base.CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveRight);
            }
            rect = WindowsFormsUtils.ConstrainToBounds(bounds, rect);
            base.Show(rect.X, rect.Y);
        }
 protected override void OnMouseEnter(EventArgs eventargs)
 {
     this.SetFlag(1, true);
     base.Invalidate();
     if ((!base.DesignMode && this.AutoEllipsis) && (this.ShowToolTip && (this.textToolTip != null)))
     {
         System.Windows.Forms.IntSecurity.AllWindows.Assert();
         try
         {
             this.textToolTip.Show(WindowsFormsUtils.TextWithoutMnemonics(this.Text), this);
         }
         finally
         {
             CodeAccessPermission.RevertAssert();
         }
     }
     base.OnMouseEnter(eventargs);
 }
Example #19
0
        internal void ShowInTaskbar(int x, int y)
        {
            // we need to make ourselves a topmost window
            WorkingAreaConstrained = false;
            Rectangle bounds = CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveLeft);
            Rectangle screenBounds = Screen.FromRectangle(bounds).Bounds;
            if (bounds.Y < screenBounds.Y)
            {
                bounds = CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.BelowLeft);
            }
            else if (bounds.X < screenBounds.X)
            {
                bounds = CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveRight);
            }
            bounds = WindowsFormsUtils.ConstrainToBounds(screenBounds, bounds);

            Show(bounds.X, bounds.Y);
        }
Example #20
0
 protected override void OnMouseEnter(EventArgs e)
 {
     if (((!this.controlToolTip && !base.DesignMode) && (this.AutoEllipsis && this.showToolTip)) && (this.textToolTip != null))
     {
         System.Windows.Forms.IntSecurity.AllWindows.Assert();
         try
         {
             this.controlToolTip = true;
             this.textToolTip.Show(WindowsFormsUtils.TextWithoutMnemonics(this.Text), this);
         }
         finally
         {
             CodeAccessPermission.RevertAssert();
             this.controlToolTip = false;
         }
     }
     base.OnMouseEnter(e);
 }
Example #21
0
        private Rectangle DropDownDirectionToDropDownBounds(ToolStripDropDownDirection dropDownDirection, Rectangle dropDownBounds)
        {
            Point offset = Point.Empty;

            switch (dropDownDirection)
            {
            case ToolStripDropDownDirection.AboveLeft:
                offset.X = -dropDownBounds.Width + this.Width;
                offset.Y = -dropDownBounds.Height + 1;
                break;

            case ToolStripDropDownDirection.AboveRight:
                offset.Y = -dropDownBounds.Height + 1;
                break;

            case ToolStripDropDownDirection.BelowRight:
                offset.Y = this.Height - 1;
                break;

            case ToolStripDropDownDirection.BelowLeft:
                offset.X = -dropDownBounds.Width + this.Width;
                offset.Y = this.Height - 1;
                break;

            case ToolStripDropDownDirection.Right:
                offset.X = this.Width;
                if (!IsOnDropDown)
                {
                    // overlap the toplevel toolstrip
                    offset.X -= 1;
                }
                break;

            case ToolStripDropDownDirection.Left:
                offset.X = -dropDownBounds.Width;
                break;
            }

            Point itemScreenLocation = this.TranslatePoint(Point.Empty, ToolStripPointType.ToolStripItemCoords, ToolStripPointType.ScreenCoords);

            dropDownBounds.Location = new Point(itemScreenLocation.X + offset.X, itemScreenLocation.Y + offset.Y);
            dropDownBounds          = WindowsFormsUtils.ConstrainToScreenWorkingAreaBounds(dropDownBounds);
            return(dropDownBounds);
        }
        private static ArrayList FindInternal(string key, bool searchAllChildren, TreeNodeCollection collection, ArrayList nodes)
        {
            if (collection == null || nodes == null)
            {
                return(null);
            }

            var collectionCount = collection.Count;

            for (int i = 0; i < collectionCount; i++)
            {
                var node = collection[i];
                if (node == null)
                {
                    continue;
                }

                if (WindowsFormsUtils.SafeCompareStrings(node.Name, key, true))
                {
                    nodes.Add(node);
                }
            }

            if (searchAllChildren)
            {
                for (int i = 0; i < collectionCount; i++)
                {
                    var node = collection[i];
                    if (node == null)
                    {
                        continue;
                    }

                    var nodeNodes = node.Nodes;
                    if (nodeNodes != null && nodeNodes.Count > 0)
                    {
                        nodes = FindInternal(key, true, nodeNodes, nodes);
                    }
                }
            }
            return(nodes);
        }
        private ArrayList FindInternal(string key, bool searchAllChildren, TreeNodeCollection treeNodeCollectionToLookIn, ArrayList foundTreeNodes)
        {
            if ((treeNodeCollectionToLookIn == null) || (foundTreeNodes == null))
            {
                return(null);
            }

            // Perform breadth first search - as it's likely people will want tree nodes belonging
            // to the same parent close to each other.

            for (int i = 0; i < treeNodeCollectionToLookIn.Count; i++)
            {
                if (treeNodeCollectionToLookIn[i] == null)
                {
                    continue;
                }

                if (WindowsFormsUtils.SafeCompareStrings(treeNodeCollectionToLookIn[i].Name, key, /* ignoreCase = */ true))
                {
                    foundTreeNodes.Add(treeNodeCollectionToLookIn[i]);
                }
            }

            // Optional recurive search for controls in child collections.

            if (searchAllChildren)
            {
                for (int i = 0; i < treeNodeCollectionToLookIn.Count; i++)
                {
                    if (treeNodeCollectionToLookIn[i] == null)
                    {
                        continue;
                    }
                    if ((treeNodeCollectionToLookIn[i].Nodes != null) && treeNodeCollectionToLookIn[i].Nodes.Count > 0)
                    {
                        // if it has a valid child collecion, append those results to our collection
                        foundTreeNodes = FindInternal(key, searchAllChildren, treeNodeCollectionToLookIn[i].Nodes, foundTreeNodes);
                    }
                }
            }
            return(foundTreeNodes);
        }
        private Rectangle DropDownDirectionToDropDownBounds(ToolStripDropDownDirection dropDownDirection, Rectangle dropDownBounds)
        {
            Point empty = Point.Empty;

            switch (dropDownDirection)
            {
            case ToolStripDropDownDirection.AboveLeft:
                empty.X = -dropDownBounds.Width + base.Width;
                empty.Y = -dropDownBounds.Height + 1;
                break;

            case ToolStripDropDownDirection.AboveRight:
                empty.Y = -dropDownBounds.Height + 1;
                break;

            case ToolStripDropDownDirection.BelowLeft:
                empty.X = -dropDownBounds.Width + base.Width;
                empty.Y = base.Height - 1;
                break;

            case ToolStripDropDownDirection.BelowRight:
                empty.Y = base.Height - 1;
                break;

            case ToolStripDropDownDirection.Left:
                empty.X = -dropDownBounds.Width;
                break;

            case ToolStripDropDownDirection.Right:
                empty.X = base.Width;
                if (!base.IsOnDropDown)
                {
                    empty.X--;
                }
                break;
            }
            Point point2 = base.TranslatePoint(Point.Empty, ToolStripPointType.ToolStripItemCoords, ToolStripPointType.ScreenCoords);

            dropDownBounds.Location = new Point(point2.X + empty.X, point2.Y + empty.Y);
            dropDownBounds          = WindowsFormsUtils.ConstrainToScreenWorkingAreaBounds(dropDownBounds);
            return(dropDownBounds);
        }
 public int IndexOfKey(string key)
 {
     if ((key != null) && (key.Length != 0))
     {
         if ((this.IsValidIndex(this.lastAccessedIndex) && (this.imageInfoCollection[this.lastAccessedIndex] != null)) && WindowsFormsUtils.SafeCompareStrings(((ImageInfo)this.imageInfoCollection[this.lastAccessedIndex]).Name, key, true))
         {
             return(this.lastAccessedIndex);
         }
         for (int i = 0; i < this.Count; i++)
         {
             if ((this.imageInfoCollection[i] != null) && WindowsFormsUtils.SafeCompareStrings(((ImageInfo)this.imageInfoCollection[i]).Name, key, true))
             {
                 this.lastAccessedIndex = i;
                 return(i);
             }
         }
         this.lastAccessedIndex = -1;
     }
     return(-1);
 }
 public virtual int IndexOfKey(string key)
 {
     if (!string.IsNullOrEmpty(key))
     {
         if (this.IsValidIndex(this.lastAccessedIndex) && WindowsFormsUtils.SafeCompareStrings(this[this.lastAccessedIndex].Name, key, true))
         {
             return(this.lastAccessedIndex);
         }
         for (int i = 0; i < this.Count; i++)
         {
             if (WindowsFormsUtils.SafeCompareStrings(this[i].Name, key, true))
             {
                 this.lastAccessedIndex = i;
                 return(i);
             }
         }
         this.lastAccessedIndex = -1;
     }
     return(-1);
 }
            private void FindInternal(string key, bool searchAllChildren, ControlCollection controlsToLookIn, List <Control> foundControls)
            {
                try
                {
                    // Perform breadth first search - as it's likely people will want controls belonging
                    // to the same parent close to each other.
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] is null)
                        {
                            continue;
                        }

                        if (WindowsFormsUtils.SafeCompareStrings(controlsToLookIn[i].Name, key, ignoreCase: true))
                        {
                            foundControls.Add(controlsToLookIn[i]);
                        }
                    }

                    // Optional recursive search for controls in child collections.
                    if (searchAllChildren)
                    {
                        for (int i = 0; i < controlsToLookIn.Count; i++)
                        {
                            if (controlsToLookIn[i] is null)
                            {
                                continue;
                            }

                            if (controlsToLookIn[i].Controls.Count > 0)
                            {
                                // If it has a valid child collection, append those results to our collection.
                                FindInternal(key, true, controlsToLookIn[i].Controls, foundControls);
                            }
                        }
                    }
                }
                catch (Exception e) when(!ClientUtils.IsCriticalException(e))
                {
                }
            }
Example #28
0
        private void FindInternal(string key, bool searchAllChildren, ToolStripItemCollection itemsToLookIn, List <ToolStripItem> foundItems)
        {
            try
            {
                for (int i = 0; i < itemsToLookIn.Count; i++)
                {
                    if (itemsToLookIn[i] is null)
                    {
                        continue;
                    }

                    if (WindowsFormsUtils.SafeCompareStrings(itemsToLookIn[i].Name, key, ignoreCase: true))
                    {
                        foundItems.Add(itemsToLookIn[i]);
                    }
                }

                // Optional recursive search for controls in child collections.
                if (searchAllChildren)
                {
                    for (int j = 0; j < itemsToLookIn.Count; j++)
                    {
                        if (itemsToLookIn[j] is not ToolStripDropDownItem item)
                        {
                            continue;
                        }

                        if (item.HasDropDownItems)
                        {
                            // If it has a valid child collection, append those results to our collection.
                            FindInternal(key, searchAllChildren, item.DropDownItems, foundItems);
                        }
                    }
                }
            }
            catch (Exception e) when(!ClientUtils.IsCriticalException(e))
            {
            }
        }
Example #29
0
            internal void ApplySettings(TableLayoutSettings settings)
            {
                TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(settings.Owner);
                Control container = containerInfo.Container as Control;

                if ((container != null) && (this.controlsInfo != null))
                {
                    foreach (object obj2 in this.controlsInfo.Keys)
                    {
                        TableLayoutSettings.ControlInformation information = this.controlsInfo[obj2];
                        foreach (Control control2 in container.Controls)
                        {
                            if (control2 != null)
                            {
                                string             str        = null;
                                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(control2)["Name"];
                                if ((descriptor != null) && (descriptor.PropertyType == typeof(string)))
                                {
                                    str = descriptor.GetValue(control2) as string;
                                }
                                if (WindowsFormsUtils.SafeCompareStrings(str, obj2 as string, false))
                                {
                                    settings.SetRow(control2, information.Row);
                                    settings.SetColumn(control2, information.Column);
                                    settings.SetRowSpan(control2, information.RowSpan);
                                    settings.SetColumnSpan(control2, information.ColumnSpan);
                                    break;
                                }
                            }
                        }
                    }
                }
                containerInfo.RowStyles    = this.rowStyles;
                containerInfo.ColumnStyles = this.columnStyles;
                this.columnStyles          = null;
                this.rowStyles             = null;
                this.isValid = false;
            }
 protected override bool ProcessCmdKey(ref Message m, Keys keyData)
 {
     if (ToolStripManager.ModalMenuFilter.InMenuMode)
     {
         // ALT, then space should dismiss the menu and activate the system menu.
         if (keyData == Keys.Space)
         {
             // if we're focused it's ok to activate system menu
             // if we're not focused - we should not activate if we contain focus - this means a text box or something
             // has focus.
             if (Focused || !ContainsFocus)
             {
                 NotifySelectionChange(null);
                 Debug.WriteLineIf(ToolStrip.SnapFocusDebug.TraceVerbose, "[MenuStrip.ProcessCmdKey] Rolling up the menu and invoking the system menu");
                 ToolStripManager.ModalMenuFilter.ExitMenuMode();
                 // send a WM_SYSCOMMAND SC_KEYMENU + Space to activate the system menu.
                 UnsafeNativeMethods.PostMessage(WindowsFormsUtils.GetRootHWnd(this), NativeMethods.WM_SYSCOMMAND, NativeMethods.SC_KEYMENU, (int)Keys.Space);
                 return(true);
             }
         }
     }
     return(base.ProcessCmdKey(ref m, keyData));
 }