Пример #1
0
        private void ControlLocationChanged(object sender, EventArgs e)
        {
            ListPanelItem movingControl = sender as ListPanelItem;

            if (movingControl == null || !movingControl.Moving)
            {
                return;
            }

            IOrderedEnumerable <Control> SortedControls = Panel.Controls.OfType <Control>().OrderBy(control => control.Top);

            Panel.SuspendLayout();

            foreach (Control control in SortedControls)
            {
                if (control == movingControl)
                {
                    continue;
                }

                int controlMiddle = control.Top + (control.Height / 2);

                if (control.Top < _snapToTop)
                {
                    if (controlMiddle > movingControl.Top)
                    {
                        if (control.Top < _snapToTop)
                        {
                            _snapToTop = control.Top;
                        }

                        control.Top += (movingControl.Height + movingControl.Margin.Bottom);
                    }
                }
                else if (control.Top > _snapToTop + movingControl.Height)
                {
                    if (controlMiddle < movingControl.Bottom)
                    {
                        control.Top = _snapToTop;
                        _snapToTop  = control.Bottom + control.Margin.Bottom + movingControl.Margin.Top;
                    }
                }
            }

            Panel.ResumeLayout();
        }
Пример #2
0
        private void AddItem(object item)
        {
            ListPanelItem control = new ListPanelItem(item);

            control.Expand();
            control.Icon              = _itemIcon;
            control.Left              = control.Margin.Left;
            control.Top               = btnAdd.Top - btnAdd.Margin.Top + control.Margin.Top;
            control.Width             = Panel.Width - control.Margin.Horizontal;
            control.StartMove        += ControlStartingMove;
            control.EndMove          += ControlEndMove;
            control.LocationChanging += ControlLocationChanging;
            control.LocationChanged  += ControlLocationChanged;
            control.SizeChanged      += ControlSizeChanged;
            control.PropertyChanged  += ControlPropertyChanged;

            Panel.Controls.Add(control);

            control.Focus();
        }