Beispiel #1
0
        /// <summary>
        /// This method will draw the items of the DropDownList. It will draw the Icon and the text and
        /// with the indent that goes with the item
        /// </summary>
        void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }
            else
            {
                BrowserComboItem item = (BrowserComboItem)Items[e.Index];

                e.DrawBackground();
                e.DrawFocusRectangle();

                int indentOffset = indentWidth * item.Indent;

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

                Size  textSize    = e.Graphics.MeasureString(item.Text, Font).ToSize();
                int   textYOffset = (e.Bounds.Height - textSize.Height) / 2;
                Point textPoint   = new Point(
                    e.Bounds.Left + item.Image.Width + indentOffset + 2,
                    e.Bounds.Top + textYOffset);

                e.Graphics.DrawIcon(item.Image, imagePoint.X, imagePoint.Y);
                e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), textPoint);
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method will change the currentItem field once a new item is selected
        /// </summary>
        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            base.OnSelectedIndexChanged(e);

            if (ComboBox.SelectedIndex > -1)
            {
                currentItem = ComboBox.SelectedItem as BrowserComboItem;
            }
        }