Exemplo n.º 1
0
 /// <summary>
 /// This method will change the currentItem field once a new item is selected
 /// </summary>
 protected override void OnSelectedIndexChanged(EventArgs e)
 {
     if (SelectedIndex >= 0)
         m_currentItem = SelectedItem as LookInComboBoxItem;
     
     base.OnSelectedIndexChanged(e);
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method will change the currentItem field once a new item is selected
        /// </summary>
        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            if (SelectedIndex >= 0)
            {
                m_currentItem = SelectedItem as LookInComboBoxItem;
            }

            base.OnSelectedIndexChanged(e);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method will draw the items of the DropDownList. It will draw the icon, the text and
        /// with the indent that goes with the item
        /// </summary>
        private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1) // The combo box contains no items and the item is the editing portion
            {
                if (m_currentItem == null)
                {
                    return;
                }

                Brush backBrush = new SolidBrush(SystemColors.Window);
                e.Graphics.FillRectangle(backBrush, e.Bounds);
                backBrush.Dispose();

                int   imageYOffset = (e.Bounds.Height - m_currentItem.Icon.Height) / 2;
                Point imagePoint   = new Point(
                    e.Bounds.Left + 2,
                    e.Bounds.Top + imageYOffset);

                Size  textSize    = TextRenderer.MeasureText(m_currentItem.Text, e.Font);
                int   textYOffset = (e.Bounds.Height - textSize.Height) / 2;
                Point textPoint   = new Point(
                    e.Bounds.Left + m_currentItem.Icon.Width + 5,
                    e.Bounds.Top + textYOffset);
                textSize.Height += textYOffset;
                Rectangle textRect = new Rectangle(textPoint, textSize);

                bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);
                if (selected)
                {
                    Brush selectedBrush = new SolidBrush(SystemColors.Highlight);
                    e.Graphics.FillRectangle(selectedBrush, textRect);
                    selectedBrush.Dispose();
                }

                if (((e.State & DrawItemState.Focus) == DrawItemState.Focus) && ((e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect))
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, textRect, e.ForeColor, e.BackColor);
                }

                e.Graphics.DrawIcon(selected ? m_currentItem.SelectedIcon : m_currentItem.Icon, imagePoint.X, imagePoint.Y);
                TextRenderer.DrawText(e.Graphics, m_currentItem.Text, e.Font, textPoint, e.ForeColor);
            }
            else
            {
                LookInComboBoxItem item = (LookInComboBoxItem)Items[e.Index];

                Brush backBrush = new SolidBrush(SystemColors.Window);
                e.Graphics.FillRectangle(backBrush, e.Bounds);
                backBrush.Dispose();

                int indentOffset = m_indentWidth * item.Indent;

                if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
                {
                    indentOffset = 0;
                }

                int   imageYOffset = (e.Bounds.Height - item.Icon.Height) / 2;
                Point imagePoint   = new Point(
                    e.Bounds.Left + indentOffset + 2,
                    e.Bounds.Top + imageYOffset);

                Size  textSize    = TextRenderer.MeasureText(item.Text, e.Font);
                int   textYOffset = (e.Bounds.Height - textSize.Height) / 2;
                Point textPoint   = new Point(
                    e.Bounds.Left + item.Icon.Width + indentOffset + 5,
                    e.Bounds.Top + textYOffset);
                textSize.Height += textYOffset;
                Rectangle textRect = new Rectangle(textPoint, textSize);

                bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);
                if (selected)
                {
                    Brush selectedBrush = new SolidBrush(SystemColors.Highlight);
                    e.Graphics.FillRectangle(selectedBrush, textRect);
                    selectedBrush.Dispose();
                }

                if (((e.State & DrawItemState.Focus) == DrawItemState.Focus) && ((e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect))
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, textRect, e.ForeColor, e.BackColor);
                }

                e.Graphics.DrawIcon(selected ? item.SelectedIcon : item.Icon, imagePoint.X, imagePoint.Y);
                TextRenderer.DrawText(e.Graphics, item.Text, e.Font, textPoint, e.ForeColor);
            }
        }