Example #1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (columnSizingState == ColumnSizingState.Active)
                {
                    columnSizingState = ColumnSizingState.Normal;
                    Cursor            = Cursors.Default;
                    Invalidate();
                }
                else if (statePressedCheckBox != null)
                {
                    statePressedCheckBox.StateCheckBox = ItemCheckBoxState.Normal;

                    if (statePressedCheckBox.BoundsCheckBox.Contains(e.Location))
                    {
                        statePressedCheckBox.CheckState = (statePressedCheckBox.CheckState == CheckState.Unchecked
                            ? CheckState.Checked
                            : CheckState.Unchecked);
                    }

                    statePressedCheckBox = null;

                    Invalidate();
                }
            }

            base.OnMouseUp(e);
        }
Example #2
0
        protected override void OnMouseLeave(EventArgs e)
        {
            bool invalidate = false;

            if (stateHotItem != null)
            {
                stateHotItem = null;
                invalidate   = true;
            }

            if (columnSizingState != ColumnSizingState.Normal)
            {
                columnSizingState = ColumnSizingState.Normal;
                invalidate        = true;
            }

            if (invalidate)
            {
                Invalidate();
            }

            base.OnMouseLeave(e);
        }
Example #3
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            Focus();

            if (e.Button == MouseButtons.Left)
            {
                if (columnSizingState == ColumnSizingState.Hot)
                {
                    columnSizingState = ColumnSizingState.Active;

                    int x = ClientRectangleInner.Width - (descriptionWidth + 6 - 2);
                    columnSizingOffset = e.X - x;

                    Invalidate();
                }
                else if (stateHotItem != null)
                {
                    if (stateHotItem.CheckEnabled && stateHotItem.StateCheckBox == ItemCheckBoxState.Hot)
                    {
                        stateHotItem.StateCheckBox = ItemCheckBoxState.Pressed;
                        statePressedCheckBox       = stateHotItem;
                        Invalidate();
                    }
                    else if (stateHotItem.BoundsIcon.Contains(e.Location))
                    {
                        Item i = stateHotItem;

                        using (ColorDialog dialog = new ColorDialog()) {
                            dialog.Color = i.Color;
                            dialog.ShowDialog(this);
                            i.Color = dialog.Color;

                            Invalidate();
                        }
                    }
                    else
                    {
                        stateFocusedItem  = stateHotItem;
                        stateSelectedItem = true;

                        if (!EnsureVisible(stateFocusedItem))
                        {
                            Invalidate();
                        }

                        OnItemSelectionChanged();
                    }
                }
                else
                {
                    if (stateSelectedItem)
                    {
                        stateSelectedItem = false;

                        Invalidate();

                        OnItemSelectionChanged();
                    }
                }
            }

            base.OnMouseDown(e);
        }
Example #4
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            int x = ClientRectangleInner.Width - (descriptionWidth + 6 - 2);

            if (columnSizingState == ColumnSizingState.Active)
            {
                int newWidth = ClientRectangleInner.Width - e.X + (columnSizingOffset - 6 + 2);
                if (newWidth > descriptionMaxWidth)
                {
                    newWidth = descriptionMaxWidth;
                }
                else if (newWidth < descriptionMinWidth)
                {
                    newWidth = descriptionMinWidth;
                }

                if (descriptionWidth != newWidth)
                {
                    descriptionWidth = newWidth;
                    Invalidate();
                }
            }
            else if (items.Count > 0 && x - 5 < e.X && x + 2 > e.X)
            {
                if (columnSizingState == ColumnSizingState.Normal)
                {
                    columnSizingState = ColumnSizingState.Hot;
                    Cursor            = Cursors.SizeWE;
                    Invalidate();
                }
            }
            else
            {
                if (columnSizingState == ColumnSizingState.Hot)
                {
                    columnSizingState = ColumnSizingState.Normal;
                    Cursor            = Cursors.Default;
                    Invalidate();
                }

                int offset = (e.Y + vScrollBar.Value - 2);
                int index  = offset / (rowHeight - 1);

                if (index < 0 || index >= items.Count || e.X < ClientRectangleInner.Left + 1 || e.X > ClientRectangleInner.Width - 1)
                {
                    if (stateHotItem != null)
                    {
                        stateHotItem.StateCheckBox = ItemCheckBoxState.Normal;
                        stateHotItem = null;
                        Invalidate();
                    }
                }
                else
                {
                    bool doRepaint = false;
                    if (stateHotItem != items[index])
                    {
                        stateHotItem = items[index];
                        doRepaint    = true;
                    }

                    bool s = stateHotItem.BoundsCheckBox.Contains(e.Location);
                    if (!s && stateHotItem.StateCheckBox == ItemCheckBoxState.Hot)
                    {
                        stateHotItem.StateCheckBox = ItemCheckBoxState.Normal;
                        doRepaint = true;
                    }
                    else if (s && stateHotItem.StateCheckBox == ItemCheckBoxState.Normal)
                    {
                        stateHotItem.StateCheckBox = ItemCheckBoxState.Hot;
                        doRepaint = true;
                    }

                    if (doRepaint)
                    {
                        Invalidate();
                    }
                }
            }

            base.OnMouseMove(e);
        }