示例#1
0
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        const TextFormatFlags flags = TextFormatFlags.Left | TextFormatFlags.VerticalCenter;

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

        if (DesignMode)
        {
            e.Graphics.DrawRectangle(Pens.Red, 1, e.Bounds.Y + 1, IMAGE_WIDTH, IMAGE_WIDTH);
            var textRect = e.Bounds;
            textRect.X += IMAGE_WIDTH + 1;
            textRect.Width -= IMAGE_WIDTH + 1;
            string itemText = "AddressListBox";
            TextRenderer.DrawText(e.Graphics, itemText, e.Font, textRect, e.ForeColor, flags);
            e.DrawFocusRectangle();
         }
        else if (e.Index >= 0)
        {
            Library lib = Items[e.Index] as Library;
            if (null == lib) return;

            e.Graphics.DrawImage(lib.Thumbnail, 0, e.Bounds.Y + 1);

            var textRect = e.Bounds;
            textRect.X += IMAGE_WIDTH + 1;
            textRect.Width -= IMAGE_WIDTH + 1;

            Font fontBold = new System.Drawing.Font(e.Font, FontStyle.Bold);

            Rectangle itemRect0 = new Rectangle(textRect.X, textRect.Y, 100, 20);
            TextRenderer.DrawText(e.Graphics, "Name         ", e.Font, itemRect0, e.ForeColor, flags); itemRect0.Y += itemRect0.Height;
            TextRenderer.DrawText(e.Graphics, "Description  ", e.Font, itemRect0, e.ForeColor, flags); itemRect0.Y += itemRect0.Height;
            TextRenderer.DrawText(e.Graphics, "Author       ", e.Font, itemRect0, e.ForeColor, flags); itemRect0.Y += itemRect0.Height;
            TextRenderer.DrawText(e.Graphics, "Date created ", e.Font, itemRect0, e.ForeColor, flags); itemRect0.Y += itemRect0.Height;

            Rectangle itemRect1 = new Rectangle(textRect.X + 100, textRect.Y, 10, 20);
            TextRenderer.DrawText(e.Graphics, ":", e.Font, itemRect1, e.ForeColor, flags); itemRect1.Y += itemRect1.Height;
            TextRenderer.DrawText(e.Graphics, ":", e.Font, itemRect1, e.ForeColor, flags); itemRect1.Y += itemRect1.Height;
            TextRenderer.DrawText(e.Graphics, ":", e.Font, itemRect1, e.ForeColor, flags); itemRect1.Y += itemRect1.Height;
            TextRenderer.DrawText(e.Graphics, ":", e.Font, itemRect1, e.ForeColor, flags); itemRect1.Y += itemRect1.Height;

            Rectangle itemRect2 = new Rectangle(textRect.X + 110, textRect.Y, textRect.Width - 110, 20);
            TextRenderer.DrawText(e.Graphics, lib.Name, fontBold, itemRect2, e.ForeColor, flags); itemRect2.Y += itemRect2.Height;
            TextRenderer.DrawText(e.Graphics, lib.Description, e.Font, itemRect2, e.ForeColor, flags); itemRect2.Y += itemRect2.Height;
            TextRenderer.DrawText(e.Graphics, lib.Author, e.Font, itemRect2, e.ForeColor, flags); itemRect2.Y += itemRect2.Height;
            TextRenderer.DrawText(e.Graphics, lib.DateCreated.ToShortDateString(), e.Font, itemRect2, e.ForeColor, flags); itemRect2.Y += itemRect2.Height;
       }
    }
示例#2
0
 private void cboDbType_DrawItem(object sender, DrawItemEventArgs e)
 {
     e.DrawBackground();
     e.DrawFocusRectangle();
     if (e.Index >= 0)
     {
         string s = this.cboDbType.Items[e.Index].ToString();
         if ((((s == "DateTime") || (s == "Currency")) || ((s == "Int32") || (s == "String"))) || (s == "AnsiStringFixedLength"))
         {
             e.Graphics.DrawString(s, e.Font, Brushes.Red, e.Bounds);
         }
         else
         {
             e.Graphics.DrawString(s, e.Font, new SolidBrush(e.ForeColor), e.Bounds);
         }
     }
 }
示例#3
0
 protected override void OnDrawItem(object sender, DrawItemEventArgs e)
 {
     Brush textBrush; //Brush for the text
     Rectangle rc = e.Bounds;
     rc.X += DRAW_OFFSET;
     //Check if the item's selected
     if (e.State == DrawItemState.Selected)
     {
         e.DrawBackground(Color.DarkKhaki);
         rc.X+=1;
         rc.Y+=1;
     }
     textBrush = new SolidBrush(SystemColors.ControlText);
     //Draw item's text
     e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, textBrush,  rc);
     //Draw a 3D line underneath
     e.Graphics.DrawLine(new Pen(Color.White), 0, e.Bounds.Bottom-1, e.Bounds.Width, e.Bounds.Bottom-1);
     e.Graphics.DrawLine(new Pen(Color.Gray), 0, e.Bounds.Bottom, e.Bounds.Width, e.Bounds.Bottom);
     //Call the base's OnDrawEvent
     base.OnDrawItem (sender, e);
 }
示例#4
0
        private void CbBasePattern_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            if (e.Index >= 0)
            {
                Color  SelectedBackColor = Color.LightSeaGreen;
                string txt   = cbBasePattern.Items[e.Index].ToString();
                Color  color = txt.EndsWith("Up") ? Color.Red : Color.Blue;

                txt = txt.Replace("Up", "↗").Replace("Down", "↘");

                Graphics g     = e.Graphics;
                Brush    brush = ((e.State & DrawItemState.Selected) == DrawItemState.Selected) ?
                                 new SolidBrush(SelectedBackColor) : new SolidBrush(e.BackColor);
                Brush tBrush = new SolidBrush(color);
                g.FillRectangle(brush, e.Bounds);
                e.Graphics.DrawString(txt, e.Font, tBrush, e.Bounds, StringFormat.GenericDefault);
                brush.Dispose();
                tBrush.Dispose();
            }
            e.DrawFocusRectangle();
        }
示例#5
0
        // Draw the item.
        public void DrawItem(DrawItemEventArgs e)
        {
            // Clear the background appropriately.
            e.DrawBackground();

            // Draw the image.
            float      hgt   = e.Bounds.Height - 2 * MarginHeight;
            float      scale = hgt / Imagen.Height;
            float      wid   = Imagen.Width * scale;
            RectangleF rect  = new RectangleF(
                e.Bounds.X + MarginWidth,
                e.Bounds.Y + MarginHeight,
                wid, hgt);

            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
            e.Graphics.DrawImage(Imagen, rect);

            // Draw the text.
            // If we're drawing on the control,
            // draw only the first line of text.
            string visible_text = NombreProducto;

            // Make a rectangle to hold the text.
            wid  = e.Bounds.Width - rect.Right - 3 * MarginWidth;
            rect = new RectangleF(
                rect.Right + 2 * MarginWidth, rect.Y,
                wid, hgt);
            using (StringFormat sf = new StringFormat())
            {
                sf.Alignment                 = StringAlignment.Near;
                sf.LineAlignment             = StringAlignment.Center;
                e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                e.Graphics.DrawString(visible_text, Font, Brushes.Black, rect, sf);
            }
            //e.Graphics.DrawRectangle(Pens.Blue, Rectangle.Round(rect));

            // Draw the focus rectangle if appropriate.
            e.DrawFocusRectangle();
        }
示例#6
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index == -1 || e.Index > this.Items.Count - 1)
            {
                return;
            }

            e.DrawBackground();

            Rectangle  imageRect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height);
            RectangleF textRectF = RectangleF.FromLTRB(imageRect.Right + 2, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom);

            if (Items[e.Index] is ComboItemImage)
            {
                ComboItemImage Item = (ComboItemImage)Items[e.Index];

                if (Item.Image != null)
                {
                    e.Graphics.DrawImage(Item.Image, imageRect);
                }
            }

            SolidBrush TextBrush = new SolidBrush(this.ForeColor);

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                TextBrush.Color = SystemColors.HighlightText;
            }

            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);

            sf.LineAlignment = StringAlignment.Center;
            sf.Trimming      = StringTrimming.EllipsisCharacter;

            e.Graphics.DrawString(Items[e.Index].ToString(), this.Font, TextBrush, textRectF, sf);
            TextBrush.Dispose();

            base.OnDrawItem(e);
        }
示例#7
0
        // Draws the items into the ColorSelector object
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            if (Items.Count <= 0)
            {
                base.OnDrawItem(e);
                return;
            }
            if (e.Index < 0)
            {
                base.OnDrawItem(e);
                return;
            }
            DropDownItem item = Items[e.Index] as DropDownItem;

            // Draw the colored 16 x 16 square
            e.Graphics.DrawImage(item.Icon.ToBitmap(), e.Bounds.Left, e.Bounds.Top, 21, 21);
            e.Graphics.DrawString(item.Value, e.Font, new
                                  SolidBrush(e.ForeColor), e.Bounds.Left + item.Icon.Width, e.Bounds.Top + 2);
            base.OnDrawItem(e);
        }
示例#8
0
            void Owner_DrawItem(object sender, DrawItemEventArgs e)
            {
                e.DrawBackground();

                if (e.Index >= 0)
                {
                    var listitem = Items[e.Index];
                    if (listitem.Icon != null && ShowIcons)
                    {
                        Rectangle src  = new Rectangle(0, 0, 16, 16);
                        Rectangle dest = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, 16, 16);

                        e.Graphics.DrawImage(listitem.Icon, dest, src, GraphicsUnit.Pixel);
                    }

                    bool selected = 0 != (e.State & (DrawItemState.HotLight | DrawItemState.Selected));
                    var  brush    = selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText;

                    int textX = ShowIcons ? e.Bounds.X + 20 : e.Bounds.X + 2;
                    e.Graphics.DrawString(listitem.Text ?? string.Empty, _Owner.Font, brush, new Point(textX, e.Bounds.Y + 2));
                }
            }
示例#9
0
        private void Lbsys_DrawItem(object sender, DrawItemEventArgs e) // for system draw with ICON
        {
            e.DrawBackground();

            using (Brush textb = new SolidBrush(this.ForeColor))
            {
                Rectangle textarea = e.Bounds;

                if (imageitems != null)
                {
                    int width = imageitems.Max(x => x.Width);
                    textarea.X += width;
                    Rectangle bitmaparea = e.Bounds;
                    bitmaparea.Width = width;

                    if (e.Index < imageitems.Count)
                    {
                        e.Graphics.DrawImage(imageitems[e.Index], bitmaparea);
                    }
                }

                using (StringFormat f = new StringFormat()
                {
                    Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.NoWrap
                })
                {
                    e.Graphics.DrawString(items[e.Index], e.Font, textb, textarea, f);
                }

                if (ItemSeperators != null && Array.IndexOf(ItemSeperators, e.Index) >= 0)
                {
                    using (Pen p = new Pen(ItemSeperatorColor))
                    {
                        e.Graphics.DrawLine(p, new Point(textarea.Left, textarea.Top), new Point(textarea.Right, textarea.Top));
                    }
                }
            }
            e.DrawFocusRectangle();
        }
示例#10
0
        private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            string content = ((ListBox)sender).Items[e.Index].ToString();

            e.DrawBackground();
            Brush mybsh = Brushes.Black;

            if (content.Contains("违规操作"))
            {
                mybsh = Brushes.Red;
            }

            // 焦点框
            e.DrawFocusRectangle();
            //文本
            e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
        }
示例#11
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            try
            {
                e.DrawBackground();

                e.DrawFocusRectangle();

                if (e.Index >= 0 && e.Index < Items.Count)
                {
                    ImageComboBoxItem item = (ImageComboBoxItem)Items[e.Index];
                    e.Graphics.DrawImage(item.Image, e.Bounds.Left + 2, e.Bounds.Top + 2);
                    e.Graphics.DrawString(item.Value, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + item.Image.Width + 2, e.Bounds.Top + 1);
                }

                base.OnDrawItem(e);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#12
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();

            if (e.Index < 0)
            {
                return;
            }
            BandBase c   = Items[e.Index] as BandBase;
            Image    img = c == null?Res.GetImage(76) : RegisteredObjects.FindObject(c).Image;

            e.Graphics.DrawImage(img, e.Bounds.X + 2, e.Bounds.Y);
            using (Brush b = new SolidBrush(e.ForeColor))
            {
                string text = "";
                if (c == null)
                {
                    text = Res.Get("Misc,None");
                }
                else
                {
                    text = Res.Get(RegisteredObjects.FindObject(c).Text);
                    if (c is DataBand)
                    {
                        text += ": " + c.GetInfoText();
                    }
                    else if (c is DataFooterBand)
                    {
                        text += ": " + c.DataBand.GetInfoText();
                    }
                    else if (c is GroupFooterBand)
                    {
                        text += ": " + (c.Parent as GroupHeaderBand).GetInfoText();
                    }
                }
                e.Graphics.DrawString(text, e.Font, b,
                                      e.Bounds.X + 24, e.Bounds.Y + (e.Bounds.Height - ItemHeight) / 2);
            }
        }
示例#13
0
        private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            // Draw the background of the ListBox control for each item.
            e.DrawBackground();
            // Define the default color of the brush as black.
            Brush myBrush = Brushes.Black;

            // Determine the color of the brush to draw each item based
            // on the index of the item to draw.
            myBrush = Brushes.Gainsboro;

            // Draw the current item text based on the current Font
            // and the custom brush settings.
            try
            {
                e.Graphics.DrawString(listBox.Items[e.Index].ToString(),
                                      e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
            }

            catch { }
            // If the ListBox has focus, draw a focus rectangle around the selected item.
        }
示例#14
0
        private void lboxPatterns_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index != -1)
            {
                Brush  b;
                string text = lboxPatterns.Items[e.Index].ToString();

                e.DrawBackground();
                if (this.CurrentSong != null && this.currentSong.Looped && e.Index == this.CurrentSong.LoopToPattern)
                {
                    b    = new SolidBrush(Color.FromKnownColor(KnownColor.Red));
                    text = "* " + text;
                }
                else
                {
                    b = new SolidBrush(e.ForeColor);
                }
                e.Graphics.DrawString(text, e.Font, b, e.Bounds, StringFormat.GenericDefault);
                e.DrawFocusRectangle();
                b.Dispose();
            }
        }
        private void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            Graphics      g          = e.Graphics;
            PartitionItem item       = (PartitionItem)partitionCmb.Items[e.Index];
            Color         textColour = e.ForeColor;
            PointF        textPos    = e.Bounds.Location;

            if (item.Icon != null)
            {
                textPos.X += item.Icon.Width + 4;
            }
            textPos.Y += 1;

            //Set the text colour and background colour if the control is disabled
            if ((e.State & DrawItemState.Disabled) == 0)
            {
                e.DrawBackground();
            }
            else
            {
                g.FillRectangle(new SolidBrush(SystemColors.ButtonFace), e.Bounds);
                textColour = SystemColors.GrayText;
            }

            if (item.Icon != null)
            {
                g.DrawIcon(item.Icon, e.Bounds.X + 2, e.Bounds.Y);
            }
            g.DrawString(item.ToString(), e.Font, new SolidBrush(textColour), textPos);
            if ((e.State & DrawItemState.Focus) != 0)
            {
                e.DrawFocusRectangle();
            }
        }
示例#16
0
        public static void DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }

            ComboBox combo = sender as ComboBox;

            combo.BackColor = ThemeColorTable.ComboBoxBackColor;
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(new SolidBrush(ThemeColorTable.ComboBoxHighlightColor),
                                         e.Bounds);
                e.DrawFocusRectangle();
            }
            else
            {
                e.DrawBackground();
            }
            e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, new SolidBrush(ThemeColorTable.ForeColor), new Point(e.Bounds.X, e.Bounds.Y));
        }
示例#17
0
 /// <summary>
 /// Called to draw an item in our plugins list box. We have to do this by
 /// hand to be able to support disabled items.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event arguments.</param>
 private void PipelinePluginsLst_DrawItem(object sender, DrawItemEventArgs e)
 {
     // The code to do this has been ripped off MSDN and adapted.
     // Open help and look at the code example for the DrawItemEventArgs class.
     if (listItemRegularBrush != null)
     {
         PluginToImportDisplayInfo pluginDisplayInfo = (PluginToImportDisplayInfo)PipelinePluginsLst.Items[e.Index];
         Brush foreBrush = listItemRegularBrush;
         if (PipelinePluginsLst.SelectedIndices.Contains(e.Index))
         {
             foreBrush = listItemSelectedBrush;
         }
         else if (!pluginDisplayInfo.Importable)
         {
             foreBrush = listItemDisabledBrush;
         }
         e.DrawBackground();
         e.Graphics.DrawString(PipelinePluginsLst.Items[e.Index].ToString(), e.Font, foreBrush,
                               e.Bounds, StringFormat.GenericDefault);
         e.DrawFocusRectangle();
     }
 }
示例#18
0
        private void ComboBoxDrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox cmb = sender as ComboBox;

            if (e.Index < 0)
            {
                return;
            }
            string text = cmb.GetItemText(cmb.Items[e.Index]);

            e.DrawBackground();
            using (SolidBrush br = new SolidBrush(e.ForeColor))
            {
                e.Graphics.DrawString(text, e.Font, br, e.Bounds);
            }
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                tTEmissionData.Show(text, cmb, e.Bounds.Right, e.Bounds.Bottom);
            }

            e.DrawFocusRectangle();
        }
示例#19
0
    private void toolstrip_color_draw_item(object o, DrawItemEventArgs e)
    {
        if (0 <= e.Index)
        {
            components_color color     = item_color.Items[e.Index] as components_color;
            Rectangle        rectangle = e.Bounds;
            SolidBrush       brush     = new SolidBrush(color.color);

            e.DrawBackground();

            e.Graphics.FillRectangle(brush, rectangle.Left + 1, rectangle.Top + 1, rectangle.Height - 2, rectangle.Height - 2);

            e.Graphics.DrawString(color.name, filter.Font, Brushes.Black, new RectangleF(rectangle.Left + rectangle.Height, rectangle.Top + 1, rectangle.Width - rectangle.Height, rectangle.Height));

            if (DrawItemState.Focus == e.State)
            {
                e.DrawFocusRectangle();
            }

            brush.Dispose();
        }
    }
示例#20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            object item = this.Items[e.Index];

            if (item != null)
            {
                e.DrawBackground();
                e.DrawFocusRectangle();

                Font font = new Font("Arial", 8);

                if (item.GetType() == typeof(string))
                {
                    e.Graphics.DrawString((string)item, font, System.Drawing.Brushes.Black, e.Bounds, StringFormat.GenericDefault);
                }
                else if (item.GetType() == typeof(DecoratorEntry))
                {
                    float    lineY = e.Bounds.Top + (e.Bounds.Height / 2.0f);
                    PointF[] pts   = new PointF[2];
                    pts[0] = new PointF(e.Bounds.Left + 10, lineY);
                    pts[1] = new PointF(e.Bounds.Right - 10, lineY);
                    this.itemLine.SetPoints(pts);
                    System.Type   decoratorType = ((DecoratorEntry)item).DecoratorType;
                    LineDecorator decorator     = (LineDecorator)Activator.CreateInstance(decoratorType);
                    if (decorator != null)
                    {
                        FilledLineDecorator filledDecorator = decorator as FilledLineDecorator;
                        if (filledDecorator != null)
                        {
                            filledDecorator.FillStyle.Type  = FillStyle.FillType.Solid;
                            filledDecorator.FillStyle.Color = Color.Black;
                        }
                        this.itemLine.LastEndPoint = decorator;
                        this.itemLine.Draw(e.Graphics);
                    }
                }
            }
            base.OnDrawItem(e);
        }
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        e.DrawBackground();
        if (e.State == DrawItemState.Focus)
        {
            e.DrawFocusRectangle();
        }
        var index = e.Index;

        if (index < 0 || index >= Items.Count)
        {
            return;
        }
        var    item = Items[index];
        string text = (item == null)?"(null)":item.ToString();

        using (var brush = new SolidBrush(e.ForeColor))
        {
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            e.Graphics.DrawString(text, e.Font, brush, e.Bounds);
        }
    }
示例#22
0
        private void _officerQueueListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            e.DrawBackground();
            SolidBrush brush = new SolidBrush(_officerQueueListBox.ForeColor);
            QueueEntry item  = _officerQueueListBox.Items[e.Index] as QueueEntry;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                brush.Color = item.Person is WalkIn ? Color.YellowGreen : SystemColors.HighlightText;
            }
            else
            {
                brush.Color = item.Person is WalkIn ? Color.Green : _officerQueueListBox.ForeColor;
            }
            e.Graphics.DrawString(item.VisitorName, e.Font, brush, e.Bounds, StringFormat.GenericDefault);
            e.DrawFocusRectangle();
        }
示例#23
0
        private void lbColor_DrawItem(object sender, DrawItemEventArgs e)
        {
            // element background display
            e.DrawBackground();

            // item icon and text display
            var   color = (Color)lbColor.Items[e.Index];
            Brush brush = new SolidBrush(color);

            var graphics = e.Graphics;
            int x        = e.Bounds.X;
            int y        = e.Bounds.Y;
            int w        = e.Bounds.Width;
            int h        = e.Bounds.Height;

            graphics.DrawRectangle(Pens.Black, x + 2, y + 2, 21, h - 5);
            graphics.FillRectangle(brush, x + 3, y + 3, 20, h - 6);
            graphics.DrawString(color.Name, e.Font, textBrush, x + 26, y + 2);

            // element focus display
            e.DrawFocusRectangle();
        }
        private void MyComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            try
            {
                Graphics g = e.Graphics;

                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                e.DrawBackground();

                if ((e.State & DrawItemState.Focus) != 0)
                {
                    e.DrawFocusRectangle();
                }

                g.DrawString(((Font)myComboBox.Items[e.Index]).Name, (Font)myComboBox.Items[e.Index], Brushes.Black, e.Bounds);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#25
0
        protected override void OnDrawItem(DrawItemEventArgs ea)
        {
            ea.DrawBackground();
            ea.DrawFocusRectangle();

            ComboBoxExItem item;
            Size           imageSize = imageList.ImageSize;
            Rectangle      bounds    = ea.Bounds;

            try {
                item = (ComboBoxExItem)Items[ea.Index];

                if (item.ImageIndex != -1)
                {
                    imageList.Draw(ea.Graphics, bounds.Left, bounds.Top,
                                   item.ImageIndex);
                    ea.Graphics.DrawString(item.Text, ea.Font, new
                                           SolidBrush(ea.ForeColor), bounds.Left + imageSize.Width, bounds.Top);
                }
                else
                {
                    ea.Graphics.DrawString(item.Text, ea.Font, new
                                           SolidBrush(ea.ForeColor), bounds.Left, bounds.Top);
                }
            } catch {
                if (ea.Index != -1)
                {
                    ea.Graphics.DrawString(Items[ea.Index].ToString(), ea.Font, new
                                           SolidBrush(ea.ForeColor), bounds.Left, bounds.Top);
                }
                else
                {
                    ea.Graphics.DrawString(Text, ea.Font, new
                                           SolidBrush(ea.ForeColor), bounds.Left, bounds.Top);
                }
            }

            base.OnDrawItem(ea);
        }
示例#26
0
        /// <summary>
        /// 鼠标移出控件的可见区域时触发
        /// </summary>
        protected virtual void ListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            Rectangle  r       = new Rectangle(0, 0, this.Width, this.Height); //设置重绘的区域
            SolidBrush SolidB1 = new SolidBrush(this.Color1);                  //设置上一行颜色
            SolidBrush SolidB2 = new SolidBrush(this.Color2);                  //设置下一行颜色
            //设置上一行的渐变色
            LinearGradientBrush LinearG1 = new LinearGradientBrush(r, this.Color1, this.Color1Gradual, LinearGradientMode.BackwardDiagonal);
            //设置下一行的渐变色
            LinearGradientBrush LinearG2 = new LinearGradientBrush(r, this.Color2, this.Color2Gradual, LinearGradientMode.BackwardDiagonal);

            //将单色与渐变色存入Brush数组中
            listBoxBrushes = new Brush[] { SolidB1, LinearG1, SolidB2, LinearG2 };
            e.DrawBackground();
            if (this.Items.Count <= 0)//如果当前控件为空
            {
                return;
            }
            if (e.Index == (this.Items.Count - 1))//如果绘制的是最后一个项
            {
                bool tem_bool = true;
                if (e.Index == 0 && tem_bool) //如果当前绘制的是第一个或最后一个项
                {
                    naught = false;           //不进行重绘
                }
            }
            if (naught)//对控件进行重绘
            {
                //获取当前绘制的颜色值
                Brush brush = listBoxBrushes[place = (GradualC) ? (((e.Index % 2) == 0) ? 1 : 3) : (((e.Index % 2) == 0) ? 0 : 2)];
                e.Graphics.FillRectangle(brush, e.Bounds);                                                     //用指定的画刷填充列表项范围所形成的矩形
                bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected) ? true : false; //判断当前项是否被选取中
                if (selected)                                                                                  //如果当前项被选中
                {
                    e.Graphics.FillRectangle(new SolidBrush(ColorSelect), e.Bounds);                           //绘制当前项
                }
                e.Graphics.DrawString(this.Items[e.Index].ToString(), this.Font, Brushes.Black, e.Bounds);     //绘制当前项中的文本
            }
            e.DrawFocusRectangle();                                                                            //绘制聚焦框
        }
示例#27
0
        public static void DrawCenterComboBox(object sender, DrawItemEventArgs e)
        {
            if (sender is ComboBox cbx)
            {
                e.DrawBackground();

                if (e.Index >= 0)
                {
                    var brush = new SolidBrush(cbx.ForeColor);

                    if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                    {
                        brush = SystemBrushes.HighlightText as SolidBrush;
                    }

                    e.Graphics.DrawString(cbx.Items[e.Index].ToString(), cbx.Font, brush, e.Bounds, new StringFormat {
                        LineAlignment = StringAlignment.Center,
                        Alignment     = StringAlignment.Center
                    });
                }
            }
        }
示例#28
0
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            ListBoxItemInfo it = listBox1.Items[e.Index] as ListBoxItemInfo;

            Brush weightBrush;

            e.DrawBackground();
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {// 如果被选中,则画出聚焦框
                e.DrawFocusRectangle();

                weightBrush = Brushes.Black;
            }
            else
            {// 否则根据item存储的颜色来画背景色
                Brush br = new SolidBrush(it.BackColor);
                //Brush br = new SolidBrush(Color.Yellow);
                e.Graphics.FillRectangle(br, e.Bounds);

                weightBrush = Brushes.Gray;
            }

            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

            // 设置item的显示信息格式
            var powderFont = new Font("微软雅黑", 16, FontStyle.Bold);

            e.Graphics.DrawString(it.PowderName, powderFont, Brushes.Black,
                                  e.Bounds, null);

            var standardWeightFont = new Font("微软雅黑", 10, FontStyle.Regular);

            e.Graphics.DrawString("标准质量为:" + it.StandardQuality + "g", standardWeightFont,
                                  weightBrush, e.Bounds.Left + 3, e.Bounds.Top + 32);
        }
示例#29
0
        void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (!languageComboBox.DroppedDown)
            {
                e.Graphics.DrawRectangle(Pens.White, e.Bounds);
            }
            else
            {
                e.DrawBackground();

                if (e.Index == languageComboBox.Items.Count - (1 + lineOffset))
                {
                    e.Graphics.DrawLine(Pens.DarkGray, new Point(e.Bounds.Left, e.Bounds.Bottom - 1),
                                        new Point(e.Bounds.Right, e.Bounds.Bottom - 1));
                }
            }

            if (e.Index != -1)
            {
                string text;
                Color  color;

                if (languageComboBox.Items[e.Index] is CultureInfo)
                {
                    text  = ((CultureInfo)languageComboBox.Items[e.Index]).DisplayName;
                    color = languageComboBox.ForeColor;
                }
                else
                {
                    text  = languageComboBox.Items[e.Index].ToString();
                    color = Color.DarkBlue;
                }

                TextRenderer.DrawText(e.Graphics, text, languageComboBox.Font, e.Bounds,
                                      color, TextFormatFlags.Left);
            }

            e.DrawFocusRectangle();
        }
示例#30
0
        private void productList_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }
            else
            {
                e.DrawBackground();
                Brush        textBrush = SystemBrushes.ControlText;
                Font         drawFont  = e.Font;
                ComboBoxData eIdType   = (ComboBoxData)carrierList.Items[e.Index];
                string       strToShow = eIdType.Description.ToString();
                if ((e.State & DrawItemState.Selected) > 0)
                {
                    textBrush = SystemBrushes.HighlightText;
                }

                e.Graphics.DrawString(strToShow, drawFont, textBrush, e.Bounds);
                e.DrawFocusRectangle();
            }
        }
示例#31
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);

            if (e.Index > -1 && e.Index < this.Items.Count)
            {
                e.DrawBackground();

                if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
                {
                    e.DrawFocusRectangle();
                }

                using (SolidBrush textBrush = new SolidBrush(e.ForeColor))
                {
                    string fontFamilyName;

                    fontFamilyName = this.Items[e.Index].ToString();
                    e.Graphics.DrawString(fontFamilyName, this.GetFont(fontFamilyName), textBrush, e.Bounds, _stringFormat);
                }
            }
        }
示例#32
0
        public static void DrawComboBoxCentered(object sender, DrawItemEventArgs e)
        {
            ComboBox combo = (ComboBox)sender;

            if (combo == null)
            {
                return;
            }
            e.DrawBackground();
            if (e.Index >= 0)
            {
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment     = StringAlignment.Center;
                Brush brush = new SolidBrush(combo.ForeColor);
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    brush = SystemBrushes.HighlightText;
                }
                e.Graphics.DrawString(combo.Items[e.Index].ToString(), combo.Font, brush, e.Bounds, sf);
            }
        }
示例#33
0
 protected override void OnDrawItem(DrawItemEventArgs e)
 {
     try
     {
         if (e.Index == -1 || e.Index >= this.Items.Count)
         {
             return;
         }
         Annotation a = this.Items[e.Index] as Annotation;
         if (a == null)
         {
             return;
         }
         e.DrawBackground();
         bool selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
         Annotations.Render(a, e.Bounds, this.Font, e.Graphics, selected, true);
     }
     catch (Exception ex)
     {
         LabyrinthData.Log((object)ex);
     }
 }
示例#34
0
   protected override void OnDrawItem(DrawItemEventArgs itemEventArgs)
   {
      itemEventArgs.DrawBackground();
      itemEventArgs.DrawFocusRectangle();

      ComboBoxExItem item;
      System.Drawing.Size imageSize = m_ImageList.ImageSize;
      System.Drawing.Rectangle bounds = itemEventArgs.Bounds;

      try
      {
         item = (ComboBoxExItem)Items[itemEventArgs.Index];

         if(item.ImageIndex != -1)
         {
            m_ImageList.Draw(itemEventArgs.Graphics,bounds.Left,bounds.Top,item.ImageIndex);

            itemEventArgs.Graphics.DrawString(item.Text,itemEventArgs.Font,new SolidBrush(itemEventArgs.ForeColor),bounds.Left+imageSize.Width,bounds.Top);
         }
         else
         {
            itemEventArgs.Graphics.DrawString(item.Text,itemEventArgs.Font,new SolidBrush(itemEventArgs.ForeColor),bounds.Left,bounds.Top);
         }
      }
      catch
      {
         if(itemEventArgs.Index != -1)
         {
            itemEventArgs.Graphics.DrawString(Items[itemEventArgs.Index].ToString(),itemEventArgs.Font,new SolidBrush(itemEventArgs.ForeColor),bounds.Left,bounds.Top);
         }
         else
         {
            itemEventArgs.Graphics.DrawString(Text,itemEventArgs.Font,new SolidBrush(itemEventArgs.ForeColor),bounds.Left,bounds.Top);
         }
      }
      base.OnDrawItem(itemEventArgs);
   }
示例#35
0
	/// <summary>
	/// Performs custom painting for a list item.
	/// </summary>
	/// <param name="e"></param>
	protected override void OnDrawItem(DrawItemEventArgs e) {
		base.OnDrawItem(e);

		if ((e.Index >= 0) && (e.Index < Items.Count)) {
			// get noteworthy states
			bool comboBoxEdit = (e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit;
			bool selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
			bool noAccelerator = (e.State & DrawItemState.NoAccelerator) == DrawItemState.NoAccelerator;
			bool disabled = (e.State & DrawItemState.Disabled) == DrawItemState.Disabled;
			bool focus = (e.State & DrawItemState.Focus) == DrawItemState.Focus;

			// determine grouping
			string groupText;
			bool isGroupStart = IsGroupStart(e.Index, out groupText) && !comboBoxEdit;
			bool hasGroup = (groupText != String.Empty) && !comboBoxEdit;

			// the item text will appear in a different colour, depending on its state
			Color textColor;
			if (disabled)
				textColor = SystemColors.GrayText;
			else if (!comboBoxEdit && selected)
				textColor = SystemColors.HighlightText;
			else
				textColor = ForeColor;

			// items will be indented if they belong to a group
			Rectangle itemBounds = Rectangle.FromLTRB(
				e.Bounds.X + (hasGroup ? 12 : 0), 
				e.Bounds.Y + (isGroupStart ? (e.Bounds.Height / 2) : 0), 
				e.Bounds.Right, 
				e.Bounds.Bottom
			);
			Rectangle groupBounds = new Rectangle(
				e.Bounds.X, 
				e.Bounds.Y, 
				e.Bounds.Width, 
				e.Bounds.Height / 2
			);

			if (isGroupStart && selected) {
				// ensure that the group header is never highlighted
				e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
				e.Graphics.FillRectangle(new SolidBrush(BackColor), groupBounds);
			}
            else if (disabled) {
                // disabled appearance
                e.Graphics.FillRectangle(Brushes.WhiteSmoke, e.Bounds);
            }
            else if (!comboBoxEdit) {
                // use the default background-painting logic
                e.DrawBackground();
            }

			// render group header text
			if (isGroupStart) TextRenderer.DrawText(
				e.Graphics, 
				groupText, 
				_groupFont, 
				groupBounds, 
				ForeColor, 
				_textFormatFlags
			);

			// render item text
			TextRenderer.DrawText(
				e.Graphics, 
				GetItemText(Items[e.Index]), 
				Font, 
				itemBounds, 
				textColor, 
				_textFormatFlags
			);

			// paint the focus rectangle if required
			if (focus && !noAccelerator) {
				if (isGroupStart && selected) {
					// don't draw the focus rectangle around the group header
					ControlPaint.DrawFocusRectangle(e.Graphics, Rectangle.FromLTRB(groupBounds.X, itemBounds.Y, itemBounds.Right, itemBounds.Bottom));
				}
				else {
					// use default focus rectangle painting logic
					e.DrawFocusRectangle();
				}
			}
		}
	}
示例#36
0
		protected override void OnDrawItem(object sender, DrawItemEventArgs e)
		{
			Brush textBrush; //Brush for the text
			SmartListItem item; 
   
			Rectangle rc = e.Bounds;
			int autoNum = (int)rc.Y / rc.Height + 1;

			//int autoNum = e.Index + 1;

			rc.X += DRAW_OFFSET;

			//Get the SmartListItem
			if ((e.Index > -1) && (e.Index < itemList.Count))
				item = (SmartListItem)itemList[e.Index];
			else 
				return;


			//Check if the item is selected
			if (e.State == DrawItemState.Selected)
			{
				//Highlighted
				e.DrawBackground();
				textBrush = new SolidBrush(SystemColors.HighlightText);
			}
			else
			{
				

				if (this.BackgroundImage != null) // don't do background if there is back image
				{
					Rectangle rcImage = Rectangle.Empty;
					if (showLines)
						rcImage = new Rectangle(0, rc.Y + 1,  this.Width, rc.Height - 1);
					else
						rcImage = new Rectangle(0, rc.Y,  this.Width, rc.Height);

					e.Graphics.DrawImage(BackgroundImage, 1, rc.Y + 1, rcImage, GraphicsUnit.Pixel);
				}
				else
				{
					//Change the background for every even item
					if ((e.Index % 2) == 0)
					{
						e.DrawBackground(colorEvenItem);
					}
					else
					{
						e.DrawBackground(this.BackColor);
					}
					
				}
					
				textBrush = new SolidBrush(item.ForeColor);
			}
			
			int numberShift = 0;
			SizeF numSize = SizeF.Empty;

			if (autoNumbering)
			{
				numSize = e.Graphics.MeasureString("22", item.Font);
				numberShift = (int)numSize.Width + 4;

			}
			
			///Check if the item has a image
			if ((item.ImageIndex > -1) && (imageList != null))
			{
				Image img = imageList.Images[item.ImageIndex];
				if (img != null)
				{
					imageAttr = new ImageAttributes();
					//Set the transparency key
					imageAttr.SetColorKey(BackgroundImageColor(img), BackgroundImageColor(img));
					//Image's rectangle
					Rectangle imgRect = Rectangle.Empty;
					
					imgRect = new Rectangle(2 + numberShift, rc.Y + 2, img.Width, img.Height);
					//Draw the image
					e.Graphics.DrawImage(img, imgRect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imageAttr); 
					//Shift the text to the right
					rc.X+=img.Width + 2;
				}
			}
			//			

			if (autoNumbering)
			{				
				e.Graphics.DrawString(autoNum.ToString(), item.Font, textBrush,  6, rc.Top + (rc.Height - (int)numSize.Height)/2);
				rc.X+=numberShift;
			}
			//Draw item's text
			if (wrapText)
				e.Graphics.DrawString(item.Text, item.Font, textBrush,  rc);
			else
			{
				//center the text vertically
				SizeF size = e.Graphics.MeasureString(item.Text, item.Font);
				Rectangle rcText = Rectangle.Empty;

				
				rcText = new Rectangle(rc.X, rc.Y + (rc.Height - (int)size.Height)/2, rc.Width - rc.X - 3, (int)size.Height);
				
				string itemText = ShortString(item, e, rcText.Width);


				if (selected > 0)
					DrawTextSelected(e.Graphics, item, itemText, textBrush, 0, selected, rcText, e.State); 
				else
					e.Graphics.DrawString(itemText, item.Font, textBrush,  rcText);

			}

			//Draw the line
			if (showLines)
				e.Graphics.DrawLine(penLine, 0, e.Bounds.Bottom, e.Bounds.Width, e.Bounds.Bottom);
		
			textBrush.Dispose();

			//Call the base's OnDrawEvent	
			base.OnDrawItem (sender, e);
		}
示例#37
0
        protected override void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            Brush textBrush; //Brush for the text

            Rectangle rc = e.Bounds;
            rc.X += DRAW_OFFSET;
            //Check if the item is selected
            if (e.State == DrawItemState.Selected)
            {
                //Highlighted
                e.DrawBackground();
                textBrush = new SolidBrush(SystemColors.HighlightText);
            }
            else
            {
                //Change the background for every even item
                if ((e.Index % 2) == 0)
                {
                    e.DrawBackground(Color.Thistle);
                }
                else
                {

                    e.DrawBackground(this.BackColor);
                }

                textBrush = new SolidBrush(this.ForeColor);
            }

            //Get the ListItem
            ListItem item = (ListItem)this.Items[e.Index];
            //			//Check if the item has a image
            if (item.ImageIndex > -1)
            {
                Image img = imageList.Images[item.ImageIndex];
                if (img != null)
                {
                    imageAttr = new ImageAttributes();
                    //Set the transparency key
                    imageAttr.SetColorKey(BackgroundImageColor(img), BackgroundImageColor(img));
                    //imageAttr.SetColorKey(Color.White, Color.White);
                    //Image's rectangle
                    Rectangle imgRect = new Rectangle(2, rc.Y+1, img.Width, img.Height);
                    //Draw the image
                    e.Graphics.DrawImage(img, imgRect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imageAttr);
                    //Shift the text to the right
                    rc.X+=img.Width + 2;
                }
            }

            //Draw item's text
            e.Graphics.DrawString(item.Text, e.Font, textBrush,  rc);
            //Draw the line
            e.Graphics.DrawLine(new Pen(Color.Navy), 0, e.Bounds.Bottom, e.Bounds.Width, e.Bounds.Bottom);
            //Call the base's OnDrawEvent
            base.OnDrawItem (sender, e);
        }
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        try
        {

            using (var _textBrush = new SolidBrush(this.ForeColor))
            {
                this.Alignment = Alineacion;

                TabPage _tabPage = this.TabPages[e.Index];
                Rectangle _tabBounds = this.GetTabRect(e.Index);
                Brush _TextBrush;

                if (e.State != DrawItemState.Selected)
                {
                    e.DrawBackground();
                    _TextBrush = new System.Drawing.SolidBrush(e.ForeColor);

                }

                else
                {
                    using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, gradient1, gradient2, 90f))
                    {
                        e.Graphics.FillRectangle(brush, e.Bounds);
                        _TextBrush = new SolidBrush(Color.White);
                    }
                }

                Font _TabFont = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Pixel);

                StringFormat _stringFlags = new StringFormat();
                _stringFlags.Alignment = StringAlignment.Center;
                _stringFlags.LineAlignment = StringAlignment.Center;

                e.Graphics.DrawString(_tabPage.Text, _TabFont, _TextBrush, _tabBounds, new StringFormat(_stringFlags));
            }
        }

        catch { }
    }
示例#39
0
		protected override void OnDrawItem(object sender, DrawItemEventArgs e)
		{
			Brush textBrush; //Brush for the text
			ListItem item; 
   
			Rectangle rc = e.Bounds;
			rc.X += DRAW_OFFSET;


			//Get the ListItem
			if ((e.Index > -1) && (e.Index < itemList.Count))
				item = (ListItem)itemList[e.Index];
			else 
				return;


			//Check if the item is selected
			if (e.State == DrawItemState.Selected)
			{
				//Highlighted
				e.DrawBackground();
				textBrush = new SolidBrush(SystemColors.HighlightText);
			}
			else
			{
				
				//Change the background for every even item
				if ((e.Index % 2) == 0)
				{
					e.DrawBackground(colorEvenItem);
				}
				else
				{
					e.DrawBackground(this.BackColor);
				}
				

				if (this.BackgroundImage != null) // don't do back ground if there is back image
				{
					Rectangle rcImage = Rectangle.Empty;
					if (showLines)
						rcImage = new Rectangle(0, rc.Y + 1,  this.Width, rc.Height - 1);
					else
						rcImage = new Rectangle(0, rc.Y,  this.Width, rc.Height);

					e.Graphics.DrawImage(BackgroundImage, 0, rc.Y + 1, rcImage, GraphicsUnit.Pixel);
				}
						
				textBrush = new SolidBrush(item.ForeColor);
			}
			
			
			//			//Check if the item has a image
			if ((item.ImageIndex > -1) && (imageList != null))
			{
				Image img = imageList.Images[item.ImageIndex];
				if (img != null)
				{
					imageAttr = new ImageAttributes();
					//Set the transparency key
					imageAttr.SetColorKey(BackgroundImageColor(img), BackgroundImageColor(img));
					//Image's rectangle
					Rectangle imgRect = new Rectangle(2, rc.Y + 2, img.Width, img.Height);
					//Draw the image
					e.Graphics.DrawImage(img, imgRect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imageAttr); 
					//Shift the text to the right
					rc.X+=img.Width + 4;
				}
			}
			
			//Draw item's text
			if (wrapText)
				e.Graphics.DrawString(item.Text, item.Font, textBrush,  rc);
			else
			{
				//center the text vertically
				SizeF size = e.Graphics.MeasureString(item.Text, item.Font);
				Rectangle rcText = new Rectangle(rc.X, rc.Y + (rc.Height - (int)size.Height)/2, rc.Width, (int)size.Height);
				e.Graphics.DrawString(item.Text, item.Font, textBrush,  rcText);
			}

			if (textBrush!=null)
				textBrush.Dispose();
			//Draw the line
			if (showLines)
				e.Graphics.DrawLine(penLine, 0, e.Bounds.Bottom, e.Bounds.Width, e.Bounds.Bottom);
			//Call the base's OnDrawEvent	
			//MessageBox.Show(e.Index.ToString() + " " + item.Text);

			base.OnDrawItem (sender, e);
		}