コード例 #1
0
        protected override void OnItemCheck(ItemCheckEventArgs e)
        {
            base.OnItemCheck(e);
            if (this.isUpdatingCheckStates)
            {
                return;
            }

            BitmaskItem item = base.Items[e.Index] as BitmaskItem;

            if (item.Value == 0)
            {
                this.BitmaskValue = 0;
            }
            else if (e.NewValue == CheckState.Checked)
            {
                this.BitmaskValue |= item.Value;
            }
            else if (e.NewValue == CheckState.Unchecked)
            {
                this.BitmaskValue &= ~item.Value;
            }

            this.Accept();
        }
コード例 #2
0
        public void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.ControlKey)
            {
                this.EmitInvalidate();
            }

            if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Right || (e.KeyCode == Keys.Down && e.Control))
            {
                this.ShowDropDown();
                e.Handled = true;
            }
            else if (e.Control && e.KeyCode == Keys.C)
            {
                DataObject data = new DataObject();
                data.SetText(this.bitmaskStr);
                data.SetData(ClipboardDataFormat, this.bitmask);
                Clipboard.SetDataObject(data);
                e.Handled = true;
            }
            else if (e.Control && e.KeyCode == Keys.V)
            {
                bool  success    = false;
                ulong pasteValue = 0;
                if (Clipboard.ContainsData(ClipboardDataFormat))
                {
                    pasteValue = (ulong)Clipboard.GetData(ClipboardDataFormat);
                    success    = true;
                }
                else if (Clipboard.ContainsText())
                {
                    string[] pasteObj = Clipboard.GetText().Split(new [] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string p in pasteObj)
                    {
                        if (p == null)
                        {
                            continue;
                        }
                        BitmaskItem item = this.dropdownItems.FirstOrDefault(obj => obj != null && p == obj.ToString());
                        if (item != null)
                        {
                            pasteValue |= item.Value;
                            success     = true;
                        }
                    }
                }
                if (success)
                {
                    this.bitmask    = pasteValue;
                    this.bitmaskStr = this.DefaultValueStringGenerator(this.bitmask);
                    this.EmitInvalidate();
                    this.EmitEdited(this.bitmask);
                }
                else
                {
                    System.Media.SystemSounds.Beep.Play();
                }
                e.Handled = true;
            }
        }