Пример #1
0
        /// <summary>
        ///     Specify the control to display in the drop-down
        /// </summary>
        /// <param name="control">control to display</param>
        public void SetComponent(Control control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            // create the drop-down holder, if necessary
            if (_dropDownHolder == null)
            {
                _dropDownHolder = new DropDownHolder(this);
                _dropDownHolder.Font = Font;
            }

            if (_dropDown != null)
            {
                _dropDown.KeyDown -= OnDropDownKeyDown;
                _dropDown.Dispose();
            }

            _dropDown = control;

            if (_dropDown != null)
            {
                // site the control, to allow it access to services from our container
                control.Site = Site;
                control.KeyDown += OnDropDownKeyDown;
                _dropDownHolder.SetComponent(_dropDown, (_uiTypeEditor == null) ? Resizable : _uiTypeEditor.IsDropDownResizable);
            }
        }
 public DropDownHolderAccessibleObject(DropDownHolder dropDownHolder) : base(dropDownHolder)
 {
     _owningDropDownHolder = dropDownHolder;
 }
Пример #3
0
        /// <summary>
        ///     Create the edit/drop-down controls when our handle is created.
        /// </summary>
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            // create the edit box.  done before creating the button because
            // DockStyle.Right controls should be added first.
            switch (_editControlStyle)
            {
                case TypeEditorHostEditControlStyle.Editable:
                    InitializeEdit();
                    break;

                case TypeEditorHostEditControlStyle.ReadOnlyEdit:
                    InitializeEdit();
                    _edit.ReadOnly = true;
                    break;

                case TypeEditorHostEditControlStyle.InstructionLabel:
                    InitializeInstructionLabel();
                    UpdateInstructionLabelText();
                    break;
            }

            // create the drop-down button
            if (EditStyle != UITypeEditorEditStyle.None)
            {
                _button = new DropDownButton();
                _button.Dock = DockStyle.Right;
                _button.FlatStyle = FlatStyle.Flat;
                _button.FlatAppearance.BorderSize = 0;
                _button.FlatAppearance.MouseDownBackColor
                    = VSColorTheme.GetThemedColor(EnvironmentColors.ComboBoxButtonMouseDownBackgroundColorKey);
                _button.FlatAppearance.MouseOverBackColor
                    = VSColorTheme.GetThemedColor(EnvironmentColors.ComboBoxButtonMouseOverBackgroundColorKey);

                // only allow focus to go to the drop-down button if we don't have an edit control.
                // if we have an edit control, we want this to act like a combo box, where only the edit control
                // is focusable.  If there's no edit control, though, we need to make sure the button can be 
                // focused, to prevent WinForms from forwarding focus somewhere else.
                _button.TabStop = _edit == null;

                if (_editStyle == UITypeEditorEditStyle.DropDown)
                {
                    _button.Image = CreateArrowBitmap();
                    // set button name for accessibility purposes.
                    _button.AccessibleName = VirtualTreeStrings.GetString(VirtualTreeStrings.DropDownButtonAccessibleName);
                }
                else if (_editStyle == UITypeEditorEditStyle.Modal)
                {
                    _button.Image = CreateDotDotDotBitmap();

                    // set button name for accessibility purposes.
                    _button.AccessibleName = VirtualTreeStrings.GetString(VirtualTreeStrings.BrowseButtonAccessibleName);
                }
                // Bug 17449 (Currituck). Use the system prescribed one, property grid uses this approach in 
                // ndp\fx\src\winforms\managed\system\winforms\propertygridinternal\propertygridview.cs 
                _button.Size = new Size(SystemInformation.VerticalScrollBarArrowHeight, Font.Height);

                _button.BackColor = VSColorTheme.GetThemedColor(EnvironmentColors.ComboBoxBackgroundColorKey);

                Controls.Add(_button);
                _button.Click += OnDropDownButtonClick;
                _button.LostFocus += OnContainedControlLostFocus;
            }

            // Create the drop down control container.  Check for null here because this
            // may have already been created via a call to SetComponent.
            if (_dropDownHolder == null
                && EditStyle == UITypeEditorEditStyle.DropDown)
            {
                _dropDownHolder = new DropDownHolder(this);
                _dropDownHolder.Font = Font;
            }
        }