Beispiel #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;
       }
    }
 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);
         }
     }
 }
Beispiel #3
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);
   }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Rectangle rect = e.Bounds;
            Graphics  g    = e.Graphics;

            //DDL fix
            if (e.Index == -1)
            {
                return;
            }

            //ClearType
            try
            {
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            if (_palette == null)
            {
                EventArgs Ev = new EventArgs();
                OnGlobalPaletteChanged(this, Ev);
            }

            //set colors
            if (_persistentColors == false)
            {
                //init color values
                if (_useStyledColors == true)
                {
                    _gradientStartColor = Color.FromArgb(255, 246, 215);
                    _gradientEndColor   = Color.FromArgb(255, 213, 77);
                }
                else
                {
                    _gradientStartColor = _palette.ColorTable.StatusStripGradientBegin;
                    _gradientEndColor   = _palette.ColorTable.OverflowButtonGradientEnd;
                }
            }

            //BackColors
            Color gradStartColor = _gradientStartColor;
            Color gradEndColor   = _gradientEndColor;
            Color textColor      = _palette.ColorTable.StatusStripText;

            // Retrieve the item font. If the item font has not been set,
            // use the ComboBox font.
            Font itemFont = e.Font;

            if (itemFont == null)
            {
                itemFont = this.Font;
            }

            // Draw the background of the item.
            e.DrawBackground();

            // Draw each string in the array, using a different size, color,
            // and font for each item.

            string str = (string)this.Items[e.Index];

            e.Graphics.DrawString(str, itemFont, new SolidBrush(this.ForeColor), e.Bounds);

            if ((e.State & DrawItemState.Selected) != 0)
            {
                //DrawingMethods.DrawBlendGradient(e.Graphics, e.Bounds, gradStartColor, gradEndColor, gradMiddleColor, 90F);
                DrawingMethods.DrawGradient(g, e.Bounds, gradStartColor, gradEndColor, 90F, false, Color.White, 0);
                e.Graphics.DrawString(str, itemFont, new SolidBrush(textColor), e.Bounds);
                e.DrawFocusRectangle();
            }

            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }
Beispiel #5
0
        private void listBoxVisitedCities_DrawItem(object sender, DrawItemEventArgs e)
        {
            // Get the ListBox and the item.
            ListBox lst = sender as ListBox;
            City    vc  = (City)lst.Items[e.Index];

            // Draw the background.
            e.DrawBackground();

            int index = 0;

            if (vc.Visited)
            {
                index = 1;
            }

            Image cityicon = CitiesImg[index];

            // Draw the picture.
            float      scale       = VisitedCitiesPictureHeight / cityicon.Height;
            RectangleF source_rect = new RectangleF(0, 0, cityicon.Width, cityicon.Height);

            float picture_width = scale * cityicon.Width;

            RectangleF dest_rect = new RectangleF(e.Bounds.Left + VisitedCitiesItemMargin, e.Bounds.Top + VisitedCitiesItemMargin, picture_width, VisitedCitiesPictureHeight);

            e.Graphics.DrawImage(cityicon, dest_rect, source_rect, GraphicsUnit.Pixel);
            ////

            // See if the item is selected.
            Brush br;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                br = SystemBrushes.HighlightText;
            }
            else
            {
                br = new SolidBrush(e.ForeColor);
            }

            // Find the area in which to put the text.
            float      x           = e.Bounds.Left + picture_width + 3 * VisitedCitiesItemMargin;
            float      y           = e.Bounds.Top + VisitedCitiesItemMargin * 2;
            float      width       = e.Bounds.Right - VisitedCitiesItemMargin - x;
            float      height      = e.Bounds.Bottom - VisitedCitiesItemMargin - y;
            RectangleF layout_rect = new RectangleF(x, y, width, height);

            // Draw the text.
            string txt = "";//, DisplayCityName = "";

            //CitiesLngDict.TryGetValue(vc.CityName, out string value);

            /*
             * DisplayCityName = vc.CityNameTranslated;
             *
             * if (DisplayCityName != null && DisplayCityName != "")
             *  txt = DisplayCityName;
             * else
             * {
             *  txt = vc.CityName + " -nt";
             * }
             */
            txt = vc.CityNameTranslated;
            e.Graphics.DrawString(txt, Font, br, layout_rect);

            // Draw the focus rectangle if appropriate.
            e.DrawFocusRectangle();
        }
Beispiel #6
0
 // Token: 0x0600010C RID: 268 RVA: 0x00002864 File Offset: 0x00000A64
 static void smethod_5(DrawItemEventArgs drawItemEventArgs_0)
 {
     drawItemEventArgs_0.DrawFocusRectangle();
 }
        /// <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();
                }

                /*
                 * var backgroundColor = new SolidBrush(BackColor);
                 *
                 * if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                 * {
                 *  if (e.Index < 1)
                 *  {
                 *      backgroundColor = new SolidBrush(Color.White);
                 *  }
                 *  else
                 *  {
                 *      backgroundColor = new SolidBrush(Color.SandyBrown);
                 *  }
                 *
                 * }
                 * else
                 * {
                 *  backgroundColor = new SolidBrush(BackColor);
                 * }
                 */


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

                if (!Focused)
                {
                    itemBounds.Inflate(2, 0);
                }

                if (e.Index < 1)
                {
                    var txt = new Font(new FontFamily("Lato"), 9.25f);
                    var clr = Color.Gray;

                    e.Graphics.FillRectangle(new SolidBrush(BackColor), itemBounds);
                    TextRenderer.DrawText(
                        e.Graphics,
                        GetItemText(Items[e.Index]),
                        txt,
                        itemBounds,
                        clr,
                        _textFormatFlags
                        );
                }
                else
                {
                    // render item text
                    TextRenderer.DrawText(
                        e.Graphics,
                        GetItemText(Items[e.Index]),
                        Font,
                        itemBounds,
                        textColor,
                        _textFormatFlags
                        );

                    int vertScrollBarWidth = (Items.Count > MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;

                    int newWidth = (int)e.Graphics.MeasureString(GetItemText(Items[e.Index]), Font).Width + vertScrollBarWidth;
                    newWidth += 20;
                    if (newWidth > DropDownWidth)
                    {
                        DropDownWidth = newWidth;
                    }
                }


                // 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();
                    }
                }
            }
        }
Beispiel #8
0
 private void lbViewFiles_DrawItem(object sender, DrawItemEventArgs e)
 {
     e.DrawBackground();
     e.DrawFocusRectangle();
     e.Graphics.DrawString(lbViewFiles.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
 }
Beispiel #9
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            // get post-source we are rendering
            IPostEditorPostSource postSource = (Items[e.Index] as PostSourceItem).PostSource;

            // determine image and text to use
            Image postSourceImage;

            if (e.Index == _draftsIndex)
            {
                postSourceImage = _showLargeIcons ? _draftsImageLarge : _draftsImage;
            }
            else if (e.Index == _recentPostsIndex)
            {
                postSourceImage = _showLargeIcons ? _recentPostsImageLarge : _recentPostsImage;
            }
            else
            {
                postSourceImage = _showLargeIcons ? _weblogImageLarge : _weblogImage;
            }


            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            if (_showLargeIcons)
            {
                // center the image within the list box
                int imageLeft = e.Bounds.Left + ((e.Bounds.Width / 2) - (ScaleX(postSourceImage.Width) / 2));
                int imageTop  = e.Bounds.Top + ScaleY(LARGE_TOP_INSET);
                g.DrawImage(false, postSourceImage, new Rectangle(imageLeft, imageTop, ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

                // setup string format
                TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.HorizontalCenter;

                // calculate standard text drawing metrics
                int leftMargin = ScaleX(ELEMENT_PADDING);
                int topMargin  = imageTop + ScaleY(postSourceImage.Height) + ScaleY(ELEMENT_PADDING);
                int fontHeight = g.MeasureText(postSource.Name, e.Font).Height;

                // caption
                // calculate layout rectangle
                Rectangle layoutRectangle = new Rectangle(
                    leftMargin,
                    topMargin,
                    e.Bounds.Width - (2 * ScaleX(ELEMENT_PADDING)),
                    fontHeight * TITLE_LINES);

                // draw caption
                g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat);
            }
            else
            {
                // draw post icon
                g.DrawImage(false, postSourceImage,
                            new Rectangle(e.Bounds.Left + ScaleX(ELEMENT_PADDING), e.Bounds.Top + ScaleY(SMALL_TOP_INSET),
                                          ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

                // setup string format
                TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;

                // calculate standard text drawing metrics
                int leftMargin = ScaleX(ELEMENT_PADDING) + ScaleX(postSourceImage.Width) + ScaleX(ELEMENT_PADDING);
                int topMargin  = e.Bounds.Top + ScaleY(SMALL_TOP_INSET);
                int fontHeight = g.MeasureText(postSource.Name, e.Font).Height;

                // caption
                // calculate layout rectangle
                Rectangle layoutRectangle = new Rectangle(
                    leftMargin,
                    topMargin,
                    e.Bounds.Width - leftMargin - ScaleX(ELEMENT_PADDING),
                    fontHeight * TITLE_LINES);

                // draw caption
                g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat);
            }

            // draw focus rectange if necessary
            e.DrawFocusRectangle();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.ComboBox.DrawItem"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data. </param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index < 0 || DesignMode)
            {
                base.OnDrawItem(e);
                return;
            }

            e.DrawBackground();

            var   boundsRect = e.Bounds;
            Image icon       = FilterItemOnProperty(Items[e.Index], "Icon") as Image;
            var   lastRight  = OwningColumn.CategoryColumnName == null || e.State.HasFlag(DrawItemState.ComboBoxEdit) || icon != null ? 0 : IndentSize;

            var drawUncategorizedItemSpecial = IsUncategorizedItemSpecial(e.Index);

            if (e.State.HasFlag(DrawItemState.ComboBoxEdit))
            {
                if (drawUncategorizedItemSpecial)
                {
                    return;
                }
                boundsRect.Height--;
            }

            Color brushForeColor = Color.Black;

            if ((e.State & DrawItemState.Selected) == 0)
            {
                // Item is not selected. Use BackColorOdd & BackColorEven
                var backColor = Convert.ToBoolean(e.Index % 2) ? BackColorOdd : BackColorEven;
                using (var brushBackColor = new SolidBrush(backColor))
                    e.Graphics.FillRectangle(brushBackColor, boundsRect);
            }

            Font font;

            object category;

            if (IsItemFirstInCategory(e.Index, out category) && !e.State.HasFlag(DrawItemState.ComboBoxEdit))
            {
                var categoryRect = new Rectangle(boundsRect.X, boundsRect.Y, boundsRect.Width, boundsRect.Height / 2);
                if ((e.State & DrawItemState.Selected) != 0)
                {
                    // Item is selected. Repaint background for the category portion of the line.
                    using (var brushBackColor = new SolidBrush(Color.White))
                        e.Graphics.FillRectangle(brushBackColor, categoryRect);
                }

                var sCategory = Convert.ToString(category);
                font = OwningColumn.FontForCategories ?? Font;
                using (var brush = new SolidBrush(brushForeColor))
                {
                    if (e.Index > 0)
                    {
                        using (var linePen = new Pen(SystemColors.GrayText))
                            e.Graphics.DrawLine(linePen, categoryRect.X, categoryRect.Y, categoryRect.Right, categoryRect.Y);
                    }
                    categoryRect.Y      += kSeparatorLineHeight;
                    categoryRect.Height -= kSeparatorLineHeight;
                    e.Graphics.DrawString(sCategory, font, brush, categoryRect);
                }
                boundsRect.Y       = categoryRect.Bottom;
                boundsRect.Height -= categoryRect.Height;
            }

            if ((e.State & DrawItemState.Selected) != 0)
            {
                // Item is selected. Use ForeColor = White
                brushForeColor = Color.White;
            }

            if (e.State.HasFlag(DrawItemState.ComboBoxEdit))
            {
                lastRight += 2;
            }

            font = Font;
            if (drawUncategorizedItemSpecial)
            {
                if (OwningColumn.FontForUncategorizedItems != null)
                {
                    font = OwningColumn.FontForUncategorizedItems;
                }
            }
            else if (OwningColumn.CategoryColumnName != null)
            {
                boundsRect.Width -= IndentSize;
            }

            using (var linePen = new Pen(SystemColors.GrayText))
            {
                using (var brush = new SolidBrush(brushForeColor))
                {
                    if (ColumnNames.Count == 0)
                    {
                        e.Graphics.DrawString(Convert.ToString(Items[e.Index]), font, brush, boundsRect);
                    }
                    else
                    {
                        if (drawUncategorizedItemSpecial)
                        {
                            if (e.Index > 0)
                            {
                                e.Graphics.DrawLine(linePen, boundsRect.X, boundsRect.Y, boundsRect.Right, boundsRect.Y);
                            }
                            boundsRect.Width  -= IndentSize;
                            boundsRect.Y      += kSeparatorLineHeight;
                            boundsRect.Height -= kSeparatorLineHeight;
                        }

                        if (icon != null)
                        {
                            int top    = boundsRect.Y;
                            int height = boundsRect.Height;
                            int left   = boundsRect.X;
                            int width  = IndentSize - 2;
                            if (icon.Height < height)
                            {
                                top   += ((boundsRect.Height - icon.Height) / 2);
                                height = icon.Height;
                            }
                            if (icon.Width < width)
                            {
                                left += ((boundsRect.Width - icon.Width) / 2);
                                width = icon.Width;
                            }
                            e.Graphics.DrawImage(icon, left, top, width, height);
                            lastRight += IndentSize;
                        }

                        if (drawUncategorizedItemSpecial)
                        {
                            string item = Convert.ToString(FilterItemOnProperty(Items[e.Index], "SpecialUse"));
                            boundsRect.X     = lastRight;
                            boundsRect.Width = boundsRect.Width;
                            e.Graphics.DrawString(item, font, brush, boundsRect, new StringFormat());
                        }
                        else
                        {
                            // Default (L-to-R) is to display the strings in ascending order from zero to the highest column.
                            int loopStart                    = 0;
                            Func <int, bool> notDone         = i => i < ColumnNames.Count;
                            Func <int, int>  loopIncrementer = i => i + 1;
                            StringFormat     format          = new StringFormat();

                            // If the ComboBox is displaying a RightToLeft language, draw it this way.
                            if (RightToLeft.Equals(RightToLeft.Yes))
                            {
                                // Define a StringFormat object to make the string display RTL.
                                format = new StringFormat
                                {
                                    Alignment   = StringAlignment.Near,
                                    FormatFlags = StringFormatFlags.DirectionRightToLeft
                                };

                                // Draw the strings in reverse order from high column index to zero column index.
                                loopStart       = ColumnNames.Count - 1;
                                notDone         = i => i >= 0;
                                loopIncrementer = i => i - 1;
                            }

                            for (var colIndex = loopStart; notDone(colIndex); colIndex = loopIncrementer(colIndex))
                            {
                                if (m_columnWidths[colIndex] > 0)
                                {
                                    string item = Convert.ToString(FilterItemOnProperty(Items[e.Index], ColumnNames[colIndex]));

                                    boundsRect.X     = lastRight;
                                    boundsRect.Width = m_columnWidths[colIndex];
                                    lastRight        = boundsRect.Right;
                                    e.Graphics.DrawString(item, font, brush, boundsRect, format);

                                    if (lastRight + 7 >= e.Bounds.Right)
                                    {
                                        break;
                                    }

                                    if (notDone(loopIncrementer(colIndex)) && !drawUncategorizedItemSpecial)
                                    {
                                        e.Graphics.DrawLine(linePen, boundsRect.Right - 1, boundsRect.Top, boundsRect.Right - 1, boundsRect.Bottom);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            e.DrawFocusRectangle();
        }
Beispiel #11
0
        /// <summary>Draw the bluetooth device item in the list view</summary>
        private void DrawBtDevice(DrawItemEventArgs a)
        {
            if (a.Index < 0 || a.Index >= m_lb_devices.Items.Count)
            {
                return;
            }
            var device = (Bluetooth.Device)m_lb_devices.Items[a.Index];
            var x      = a.Bounds.Left + 1;
            var y      = a.Bounds.Top + 1;

            // Get the image key for the device type
            var img_key = GetDeviceImageKey != null
                                ? GetDeviceImageKey(device)
                                : device.ClassOfDeviceMajor.ToString();

            var img = DeviceImageList.Images.ContainsKey(img_key)
                                ? DeviceImageList.Images[img_key]
                                : DeviceImageList.Images[Bluetooth.EClassOfDeviceMajor.Miscellaneous.ToString()];

            // Cell background
            if (a.State.HasFlag(DrawItemState.Selected))
            {
                using (var bsh = new SolidBrush(Color_.FromArgb(0xfff0fafe)))
                    a.Graphics.FillRectangle(bsh, a.Bounds);
            }
            else
            {
                a.DrawBackground();
            }

            // Device image
            using (a.Graphics.SaveState())
            {
                a.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                a.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                a.Graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                var aspect = (float)img.Width / img.Height;
                var cx     = aspect * (a.Bounds.Height - 2);
                var cy     = 1f * (a.Bounds.Height - 2);

                a.Graphics.DrawImage(img, new RectangleF(x, y, cx, cy));
                x = (int)(x + cx + 4);
            }

            // Device name
            using (var font = m_lb_devices.Font.Dup(em_size: 12f, style: FontStyle.Bold))
            {
                a.Graphics.DrawString(device.Name, font, Brushes.Black, new Point(x, y));
                y += font.Height;
            }

            // Device state
            using (var font = m_lb_devices.Font.Dup(em_size: 8f))
            {
                a.Graphics.DrawString(device.StatusString, font, Brushes.Blue, new Point(x, y));
                y += font.Height;
            }

            // Last used/seen
            using (var font = m_lb_devices.Font.Dup(em_size: 8f))
            {
                var s = $"Last Used: {device.LastUsed.ToString("G", CultureInfo.CurrentCulture)}";
                a.Graphics.DrawString(s, font, Brushes.Gray, new Point(x, y));
                y += font.Height;

                s = $"Last Seen: {device.LastSeen.ToString("G", CultureInfo.CurrentCulture)}";
                a.Graphics.DrawString(s, font, Brushes.Gray, new Point(x, y));
                y += font.Height;
            }

            // Focus rect
            a.DrawFocusRectangle();
        }
Beispiel #12
0
        private void AllColumns_DrawItem(object sender, DrawItemEventArgs e)
        {
            // ----- Draw a single display item.
            System.Drawing.Brush useBrush;
            DataColumn           itemDetail;
            StringFormat         ellipsesFormat;
            string columnName   = "";
            string dataTypeName = "";
            bool   isPrimaryKey = false;

            // ----- Ignore undrawable items.
            if (e.Index == -1)
            {
                return;
            }

            // ----- Draw the background of the item.
            if ((e.State & DrawItemState.Selected) != 0)
            {
                useBrush = SystemBrushes.HighlightText;
            }
            else
            {
                useBrush = SystemBrushes.WindowText;
            }
            e.DrawBackground();

            // ----- This list handles both DataColumn and string entries.
            if (AllColumns.Items[e.Index].GetType() == typeof(DataColumn))
            {
                // ----- Extract the detail from the list.
                itemDetail = (DataColumn)AllColumns.Items[e.Index];

                // ----- Extract the column details.
                columnName   = itemDetail.ColumnName;
                dataTypeName = itemDetail.DataType.ToString();
                isPrimaryKey = ((ActiveTable.PrimaryKey != null) &&
                                (ActiveTable.PrimaryKey.Contains(itemDetail) == true));

                // ----- Some data may not fit.
                ellipsesFormat          = new StringFormat();
                ellipsesFormat.Trimming = StringTrimming.EllipsisCharacter;

                // ----- Draw the text of the item.
                e.Graphics.DrawString(columnName, e.Font, useBrush,
                                      new Rectangle(ColColumnName.Left - AllColumns.Left,
                                                    e.Bounds.Top, ColDataType.Left - ColColumnName.Left - 5,
                                                    e.Bounds.Height), ellipsesFormat);
                e.Graphics.DrawString(dataTypeName, e.Font, useBrush,
                                      ColDataType.Left - AllColumns.Left, e.Bounds.Top);

                // ----- Indicate if this is a primary key column.
                if (isPrimaryKey)
                {
                    e.Graphics.DrawString("PK", e.Font, useBrush, 0, e.Bounds.Top);
                }
            }
            else
            {
                // ----- Display the string content.
                e.Graphics.DrawString((string)AllColumns.Items[e.Index],
                                      e.Font, useBrush, 0, e.Bounds.Top);
            }

            // ----- If the ListBox has focus, draw a focus rectangle.
            e.DrawFocusRectangle();
        }
Beispiel #13
0
        void FileStatusListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Bounds.Height <= 0 || e.Bounds.Width <= 0 || e.Index < 0)
            {
                return;
            }

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

            GitItemStatus gitItemStatus = (GitItemStatus)FileStatusListBox.Items[e.Index];

            e.Graphics.FillRectangle(Brushes.White, e.Bounds.Left, e.Bounds.Top, ImageSize, e.Bounds.Height);

            int centeredImageTop = e.Bounds.Top;

            if ((e.Bounds.Height - ImageSize) > 1)
            {
                centeredImageTop = e.Bounds.Top + ((e.Bounds.Height - ImageSize) / 2);
            }

            Bitmap image = null;

            if (gitItemStatus.IsDeleted)
            {
                image = Resources.Removed;
            }
            else if (gitItemStatus.IsNew || !gitItemStatus.IsTracked)
            {
                image = Resources.Added;
            }
            else if (gitItemStatus.IsChanged)
            {
                if (!gitItemStatus.IsSubmodule || gitItemStatus.SubmoduleStatus == null)
                {
                    image = Resources.Modified;
                }
                else
                {
                    var status = gitItemStatus.SubmoduleStatus;
                    if (status.IsDirty && status.Commit == status.OldCommit)
                    {
                        image = Resources.IconSubmoduleDirty;
                    }
                    else if (status.IsCommitNewer)
                    {
                        image = status.IsDirty ? Resources.IconSubmoduleRevisionUpDirty : Resources.IconSubmoduleRevisionUp;
                    }
                    else
                    {
                        image = status.IsDirty ? Resources.IconSubmoduleRevisionDownDirty : Resources.IconSubmoduleRevisionDown;
                    }
                }
            }
            else if (gitItemStatus.IsRenamed)
            {
                image = Resources.Renamed;
            }
            else if (gitItemStatus.IsCopied)
            {
                image = Resources.Copied;
            }

            if (image != null)
            {
                e.Graphics.DrawImage(image, e.Bounds.Left, centeredImageTop, ImageSize, ImageSize);
            }

            string text = GetItemText(e.Graphics, gitItemStatus);

            e.Graphics.DrawString(text, FileStatusListBox.Font,
                                  new SolidBrush(e.ForeColor), e.Bounds.Left + ImageSize, e.Bounds.Top);

            int width = (int)e.Graphics.MeasureString(text, e.Font).Width + ImageSize;

            ListBox listBox = (ListBox)sender;

            if (listBox.HorizontalExtent < width)
            {
                listBox.HorizontalExtent = width;
            }
        }
Beispiel #14
0
        public void lbPackets_DrawItem(object sender, DrawItemEventArgs e)
        {
            ListBox lb = (sender as ListBox);

            if (!(lb.Parent is PacketTabPage))
            {
                return;
            }
            PacketTabPage tp = (lb.Parent as PacketTabPage);
            PacketData    pd = null;

            if ((e.Index >= 0) && (e.Index < tp.PL.Count()))
            {
                pd = tp.PL.GetPacket(e.Index);
            }
            else
            {
                // Draw the background of the ListBox control for each item.
                e.DrawBackground();
                return;
            }

            bool  barOn      = (tp.CurrentSync == pd.PacketSync);
            bool  isSelected = (e.Index == lb.SelectedIndex);
            Color textCol;
            Color backCol;
            Color barCol;

            // Determine the color of the brush to draw each item based
            // on the index of the item to draw.
            switch (pd.PacketLogType)
            {
            case PacketLogTypes.Incoming:
                textCol = Properties.Settings.Default.ColFontIN;
                if (isSelected)
                {
                    backCol = Properties.Settings.Default.ColSelectIN;
                    textCol = Properties.Settings.Default.ColSelectedFontIN;
                }
                else
                if (barOn)
                {
                    backCol = Properties.Settings.Default.ColSyncIN;
                }
                else
                {
                    backCol = Properties.Settings.Default.ColBackIN;
                }
                barCol = Properties.Settings.Default.ColBarIN;
                break;

            case PacketLogTypes.Outgoing:
                textCol = Properties.Settings.Default.ColFontOUT;
                if (isSelected)
                {
                    backCol = Properties.Settings.Default.ColSelectOUT;
                    textCol = Properties.Settings.Default.ColSelectedFontOUT;
                }
                else
                if (barOn)
                {
                    backCol = Properties.Settings.Default.ColSyncOUT;
                }
                else
                {
                    backCol = Properties.Settings.Default.ColBackOUT;
                }
                barCol = Properties.Settings.Default.ColBarOUT;
                break;

            default:
                textCol = Properties.Settings.Default.ColFontUNK;
                if (isSelected)
                {
                    backCol = Properties.Settings.Default.ColSelectUNK;
                    textCol = Properties.Settings.Default.ColSelectedFontUNK;
                }
                else
                if (barOn)
                {
                    backCol = Properties.Settings.Default.ColSyncUNK;
                }
                else
                {
                    backCol = Properties.Settings.Default.ColBackUNK;
                }
                barCol = Properties.Settings.Default.ColBarUNK;
                break;
            }

            // Define the colors of our brushes.
            Brush textBrush = new SolidBrush(textCol);
            Brush backBrush = new SolidBrush(backCol);
            Brush barBrush  = new SolidBrush(barCol);

            // Draw the background of the ListBox control for each item.
            e.Graphics.FillRectangle(backBrush, e.Bounds);

            // Draw the current item text based on the current Font
            // and the custom brush settings.
            e.Graphics.DrawString(lb.Items[e.Index].ToString(),
                                  e.Font, textBrush, e.Bounds, StringFormat.GenericDefault);
            if (barOn)
            {
                var barSize = 8;
                if (isSelected)
                {
                    barSize = 16;
                }
                e.Graphics.FillRectangle(barBrush, new Rectangle(e.Bounds.Right - barSize, e.Bounds.Top, barSize, e.Bounds.Height));
            }
            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }
Beispiel #15
0
        private void GameListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            var list = (ListBox)sender;

            e.DrawBackground();

            if (e.Index == -1)
            {
                return;
            }
            var       index    = e.Index;
            var       room     = list.Items[index].ToString();
            var       selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);
            var       g        = e.Graphics;
            RoomInfos info     = null;

            if (m_rooms.ContainsKey(room))
            {
                info = m_rooms[room];
            }

            //item info

            string playerstring;

            if (info == null)
            {
                playerstring = "??? vs ???";
            }
            else
            {
                bool     istag   = (info.mode == 2);
                string[] players = info.playerList;

                if (players.Length == 0)
                {
                    playerstring = "??? vs ???";
                }
                else
                {
                    if (istag)
                    {
                        string player1 = players[0].Trim();
                        string player2 = (players.Length > 1) ? players[1].Trim() : "???";
                        string player3 = (players.Length > 2) ? players[2].Trim() : "???";
                        string player4 = (players.Length > 3) ? players[3].Trim() : "???";
                        playerstring = player1 + ", " + player2 + " vs " + player3 + ", " + player4;
                    }
                    else
                    {
                        string player1 = players[0].Trim();
                        string player2 = (players.Length > 1) ? players[1].Trim() : "???";

                        playerstring = player1 + " vs " + player2;
                    }
                }
            }


            var        bounds      = list.GetItemRectangle(index);
            var        rulesize    = e.Graphics.MeasureString((info == null) ? "???" : RoomInfos.GameRule(info.rule), e.Font);
            var        playersSize = e.Graphics.MeasureString(playerstring, e.Font);
            var        lockedsize  = e.Graphics.MeasureString((info == null) ? "???" : (info.isLocked ? Program.LanguageManager.Translation.GameLocked : Program.LanguageManager.Translation.GameOpen), e.Font);
            SolidBrush backgroundcolor;

            var offset = new Size(5, 5);

            if (info == null)
            {
                backgroundcolor = new SolidBrush(Color.Red);
            }
            else
            {
                backgroundcolor = new SolidBrush(info.hasStarted ? Color.LightGray :
                                                 (info.isIllegal ? Color.LightCoral :
                                                  (info.mode == 2 ? Color.LightGreen :
                                                   (info.mode == 1 ? Color.BlanchedAlmond :
                                                    Color.LightBlue))));
            }

            //draw item
            g.FillRectangle(backgroundcolor, e.Bounds);
            g.DrawLines((selected) ? new Pen(Brushes.Purple, 5) : new Pen(Brushes.Black, 5),
                        new[] { new Point(bounds.X, bounds.Y), new Point(bounds.X + bounds.Width, bounds.Y), new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height), new Point(bounds.X, bounds.Y + bounds.Height), new Point(bounds.X, bounds.Y) });
            //toplet
            g.DrawString((info == null) ? "???/???/???" : RoomInfos.GameMode(info.mode) + " / " + LauncherHelper.GetBanListFromInt(info.banListType) + " / " + (info.timer == 0 ? "3 mins" : "5 mins"), e.Font, Brushes.Black,
                         list.GetItemRectangle(index).Location + offset);
            //topright
            g.DrawString((info == null) ? "???" : RoomInfos.GameRule(info.rule), e.Font, Brushes.Black,
                         new Rectangle(bounds.X + (bounds.Width - (int)rulesize.Width) - offset.Width, bounds.Y + offset.Height, bounds.Width, bounds.Height));
            ////bottomright
            g.DrawString((info == null) ? "???" : (info.isLocked ? Program.LanguageManager.Translation.GameLocked : Program.LanguageManager.Translation.GameOpen),
                         e.Font, Brushes.Black,
                         new Rectangle(bounds.X + (bounds.Width - (int)lockedsize.Width) - offset.Width, bounds.Y + (bounds.Height - (int)lockedsize.Height) - offset.Height, bounds.Width, bounds.Height));
            //bottom center
            g.DrawString(playerstring, e.Font, Brushes.Black,
                         new Rectangle(bounds.X + ((bounds.Width / 2) - ((int)playersSize.Width / 2)), bounds.Y + (bounds.Height - (int)playersSize.Height) - offset.Height, bounds.Width, bounds.Height));
            e.DrawFocusRectangle();
        }
Beispiel #16
0
        void ListBoxEx_DrawItem(object sender, DrawItemEventArgs e)
        {
            var objItem = GetItem(e.Index);

            if (objItem == null)
            {
                return;
            }

            var item = objItem as IListBoxExItem;

            //绘制默认
            e.DrawBackground();
            e.DrawFocusRectangle();

            var startX     = ItemPadding.Left + e.Bounds.Left;
            var startY     = ItemPadding.Top + e.Bounds.Top;
            var itemWidth  = e.Bounds.Width - ItemPadding.Left - ItemPadding.Right;
            var itemHeight = e.Bounds.Height - ItemPadding.Top - ItemPadding.Bottom;

            if (item != null)
            {
                if (!item.PreventDefaultDrawing)
                {
                    if (item.Image != null)
                    {
                        e.Graphics.DrawImage(item.Image, startX,
                                             (itemHeight - item.Image.Height) / 2 + startY,
                                             item.Image.Width, item.Image.Height);
                        startX    += item.Image.Width + ImageTextSpace;
                        itemWidth -= item.Image.Width - ImageTextSpace;
                    }
                    var sizeCaption     = e.Graphics.MeasureString(item.DisplayText, ShowDescription ? CaptionFont : _listControl.Font, itemWidth);
                    var sizeDescription = string.IsNullOrEmpty(item.Description) || !ShowDescription ? (SizeF?)null : e.Graphics.MeasureString(item.Description, _listControl.Font, itemWidth);
                    //计算文字的padding
                    var textPadding = (itemHeight - (int)sizeCaption.Height - (sizeDescription.HasValue ? (int)sizeDescription.Value.Height : 0)) / 2;
                    if (textPadding < 0)
                    {
                        textPadding = 0;
                    }
                    //判断颜色
                    SolidBrush catpionBrush;
                    if (e.State.IsSelected())
                    {
                        catpionBrush = _selectedBrush;
                    }
                    else
                    {
                        if (item.ForeColor.HasValue)
                        {
                            if (!_brushCache.ContainsKey(item.ForeColor.Value))
                            {
                                catpionBrush = new SolidBrush(item.ForeColor.Value);
                                _brushCache.Add(item.ForeColor.Value, catpionBrush);
                            }
                            else
                            {
                                catpionBrush = _brushCache[item.ForeColor.Value];
                            }
                        }
                        else
                        {
                            catpionBrush = _foreBrush;
                        }
                    }

                    var textBlockSize = new SizeF(itemWidth, itemHeight);
                    //标题
                    e.Graphics.DrawString(item.DisplayText, ShowDescription ? CaptionFont : _listControl.Font, catpionBrush, new RectangleF(new PointF(startX, startY + textPadding), textBlockSize));
                    //副标题
                    if (ShowDescription && !item.Description.IsNullOrEmpty())
                    {
                        startY += (int)sizeCaption.Height + DescriptionSpace;

                        var descriptionBrush = e.State.IsSelected() ? _selectedBrush : _descriptionBrush;
                        var startPoint       = new PointF(startX, startY);
                        var region           = new RectangleF(startPoint, textBlockSize);

                        e.Graphics.DrawString(item.Description, _listControl.Font, descriptionBrush, region);
                    }
                }
                item.DrawItem(e);
            }
            else
            {
                var text = objItem.ToString();

                e.Graphics.DrawString(text, _listControl.Font, e.State.IsSelected() ? _selectedBrush : _foreBrush,
                                      new RectangleF(new PointF(startX, startY), new SizeF(e.Bounds.Width - ItemPadding.Left - ItemPadding.Right, e.Bounds.Height - ItemPadding.Top - ItemPadding.Bottom)));
            }
        }
Beispiel #17
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            string Text   = string.Empty;
            Bitmap Bitmap = null;

            // Get the Bounding rectangle
            var Rectangle = new Rectangle(e.Bounds.X + 16, e.Bounds.Y, e.Bounds.Width - 16, e.Bounds.Height);

            // Setup the StringFormat object
            var StringFormat = new StringFormat();

            // Draw the rectangle
            e.Graphics.FillRectangle(new SolidBrush(Color.White), Rectangle);

            var Rectangle1 = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
            int YOffset    = 0;

            // Get the bitmap for this entry
            if ((e.Index < this.Items.Count) && (e.Index >= 0))
            {
                Text = this.Items[e.Index].ToString();
                if (this.Items[e.Index] is ImageListItem)
                {
                    Bitmap = ((ImageListItem)this.Items[e.Index]).Image;
                }
                YOffset = (e.Bounds.Height - ((Bitmap != null) ? Bitmap.Height : 0)) / 2;
            }

            if (this.Enabled)
            {
                // Check if the item is selected
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    // Paint the item accordingly if it is selected
                    if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
                    {
                        e.DrawFocusRectangle();
                    }
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, Rectangle1);
                    if (Bitmap != null)
                    {
                        e.Graphics.DrawImage(Bitmap, e.Bounds.X, e.Bounds.Y + YOffset, Bitmap.Width, Bitmap.Height);
                    }
                    e.Graphics.DrawString(Text, this.Font, SystemBrushes.HighlightText, Rectangle, StringFormat);
                }
                else
                {
                    // Paint the item that if not selected
                    e.Graphics.FillRectangle(SystemBrushes.Window, Rectangle1);
                    if (Bitmap != null)
                    {
                        e.Graphics.DrawImage(Bitmap, e.Bounds.X, e.Bounds.Y + YOffset, Bitmap.Width, Bitmap.Height);
                    }
                    e.Graphics.DrawString(Text, this.Font, SystemBrushes.WindowText, Rectangle, StringFormat);
                    e.DrawFocusRectangle();
                }
            }
            else
            {
                // Paint the item disabled
                e.Graphics.FillRectangle(SystemBrushes.Window, Rectangle1);
                if (Bitmap != null)
                {
                    e.Graphics.DrawImage(Bitmap, e.Bounds.X, e.Bounds.Y + YOffset, Bitmap.Width, Bitmap.Height);
                }
                e.Graphics.DrawString(Text, this.Font, SystemBrushes.GrayText, Rectangle, StringFormat);
                e.DrawFocusRectangle();
            }
        }
Beispiel #18
0
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            // drawing uses double buffering to ensure good look over RDP session.
            // direct drawing to e.Graphics in DRP session disables font smoothing for some reason.
            using (var backBuffer = bufferedGraphicsContext.Allocate(e.Graphics, e.Bounds))
            {
                var g = backBuffer.Graphics;

                using (var bkBrush = new SolidBrush(e.BackColor))
                {
                    g.FillRectangle(bkBrush, e.Bounds);
                }
                if (e.Index >= 0)                 // Index was observed to be -1 once in a while!
                {
                    var li = listBox.Items[e.Index] as ListItem;
                    if (li != null)
                    {
                        var bmkImg   = StateInspectorResources.Bookmark;
                        var bmkImgSz = bmkImg.GetSize(width: UIUtils.Dpi.Scale(9));

                        bool isBookmarked = viewModel.OnGetHistoryItemBookmarked(li.evt);
                        if (isBookmarked)
                        {
                            var r = listBox.GetItemRectangle(e.Index);
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                            g.DrawImage(bmkImg, new RectangleF(1, r.Y + (r.Height - bmkImgSz.Height) / 2, bmkImgSz.Width, bmkImgSz.Height));
                        }

                        var focusedMessage = viewModel.OnDrawFocusedMessageMark();
                        if (focusedMessage != null && listBox.Items.Count != 0 && Math.Abs(focusedMessage.Item1 - e.Index) <= 1)
                        {
                            var   imgsz = UIUtils.FocusedItemMarkBounds.Size;
                            float y     = focusedMessage.Item1 >= listBox.Items.Count ?
                                          listBox.GetItemRectangle(listBox.Items.Count - 1).Bottom :
                                          listBox.GetItemRectangle(focusedMessage.Item1).Top;
                            if (focusedMessage.Item1 != focusedMessage.Item2)
                            {
                                y += listBox.ItemHeight / 2;
                            }
                            if (y == 0)
                            {
                                y += imgsz.Height / 2;
                            }
                            UIUtils.DrawFocusedItemMark(g, bmkImgSz.Width + 2, y, drawWhiteBounds: true);
                        }

                        using (var b = new SolidBrush(e.ForeColor))
                        {
                            if (strFormat == null)
                            {
                                strFormat = new StringFormat(StringFormatFlags.NoFontFallback);
                                strFormat.SetTabStops(0, new float[] { bookmarkAndFocusedMarkAreaWidth, g.MeasureString("12:23:45.678", e.Font).Width + 5 });
                            }
                            g.DrawString(li.ToString(), e.Font, b, e.Bounds.Location, strFormat);
                        }
                    }
                }

                backBuffer.Render(e.Graphics);
            }

            e.DrawFocusRectangle();
        }
Beispiel #19
0
        private void CboColorModel_DrawItem(object sender, DrawItemEventArgs e)
        {
            System.Drawing.Graphics  arg_06_0 = e.Graphics;
            System.Drawing.Rectangle bounds   = e.Bounds;
            ComboBox comboBox = (ComboBox)sender;

            if (e.Index < comboBox.Items.Count)
            {
                int arg_31_0 = e.Index;
                e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                switch (e.Index)
                {
                case 0:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width, bounds.Height - 2));
                    break;

                case 1:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 2, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X + bounds.Width / 2, bounds.Y + 1, bounds.Width / 2, bounds.Height - 2));
                    break;

                case 2:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 2, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X + bounds.Width / 2, bounds.Y + 1, bounds.Width / 2, bounds.Height - 2));
                    break;

                case 3:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X + bounds.Width / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Blue), new System.Drawing.Rectangle(bounds.X + bounds.Width * 2 / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    break;

                case 4:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Blue), new System.Drawing.Rectangle(bounds.X + bounds.Width / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X + bounds.Width * 2 / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    break;

                case 5:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X + bounds.Width / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Blue), new System.Drawing.Rectangle(bounds.X + bounds.Width * 2 / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    break;

                case 6:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Blue), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X + bounds.Width / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X + bounds.Width * 2 / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    break;

                case 7:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Blue), new System.Drawing.Rectangle(bounds.X + bounds.Width / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X + bounds.Width * 2 / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    break;

                case 8:
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Blue), new System.Drawing.Rectangle(bounds.X, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), new System.Drawing.Rectangle(bounds.X + bounds.Width / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), new System.Drawing.Rectangle(bounds.X + bounds.Width * 2 / 3, bounds.Y + 1, bounds.Width / 3, bounds.Height - 2));
                    break;
                }
                e.DrawFocusRectangle();
            }
        }
        /// <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
                var comboBoxEdit  = (e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit;
                var selected      = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
                var noAccelerator = (e.State & DrawItemState.NoAccelerator) == DrawItemState.NoAccelerator;
                var disabled      = (e.State & DrawItemState.Disabled) == DrawItemState.Disabled;
                var focus         = (e.State & DrawItemState.Focus) == DrawItemState.Focus;

                // determine grouping
                string groupText;
                var    isGroupStart = IsGroupStart(e.Index, out groupText) && !comboBoxEdit;
                var    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
                var itemBounds = Rectangle.FromLTRB(
                    e.Bounds.X + (hasGroup ? 12 : 0),
                    e.Bounds.Y + (isGroupStart ? (e.Bounds.Height / 2) : 0),
                    e.Bounds.Right,
                    e.Bounds.Bottom
                    );
                var 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, GetBackcolor(Items[e.Index]),
                    _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();
                    }
                }
            }
        }
Beispiel #21
0
        private void firmDetailsCB_DrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox box = sender as ComboBox;

            //Brush backgroundBrush, forgroundBrush;
            //if (e.State == (DrawItemState.Selected |
            //            DrawItemState.NoAccelerator | DrawItemState.NoFocusRect) ||
            //    e.State == DrawItemState.Selected)
            //{
            //    forgroundBrush = Brushes.Black;
            //    backgroundBrush = Brushes.White;
            //}
            //else
            //{
            //    forgroundBrush = Brushes.White;
            //    backgroundBrush = Brushes.Black;
            //}

            //// some way to wrap the string (on a space)
            //string str = (string)box.Items[e.Index];

            //Rectangle rc = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
            //e.Graphics.FillRectangle(forgroundBrush, rc);

            //int stringHeight = (int)e.Graphics.MeasureString(str, box.Font).Height;
            //int lineNo = 0;
            //foreach (string line in WrapString(str, e.Graphics, box.Font, e.Bounds.Width))
            //{
            //    e.Graphics.DrawString(line, box.Font, backgroundBrush, new PointF(0, lineNo * stringHeight + 5));
            //    lineNo++;
            //}
            if (e.Index < 0)
            {
                return;
            }

            // draw a lighter blue selected BG colour, the dark blue default has poor contrast with black text on a dark blue background
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(Brushes.PowderBlue, e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.White, e.Bounds);
            }

            // get the text of the item
            string text = box.Items[e.Index].ToString();

            // don't dispose the brush afterwards
            Brush b = Brushes.Black;

            e.Graphics.DrawString(text, this.Font, b, e.Bounds, StringFormat.GenericDefault);

            // draw a light grey border line to separate the items
            Pen p = new Pen(Brushes.Gainsboro, 1);

            e.Graphics.DrawLine(p, new Point(e.Bounds.Left, e.Bounds.Bottom - 1), new Point(e.Bounds.Right, e.Bounds.Bottom - 1));
            p.Dispose();

            e.DrawFocusRectangle();
        }
        /// <summary>
        /// Paint the node style representation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nodeStyleListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            ListBox listBox = (ListBox)sender;
            int     i       = e.Index;
            INode   node    = (INode)listBox.Items[i];

            node = new SimpleNode {
                Labels = node.Labels,
                Layout = node.Layout,
                Style  = node.Style,
                Tag    = node.Tag
            };
            if (node.Layout.Height > 50)
            {
                ((SimpleNode)node).Layout = RectD.FromCenter(node.Layout.GetCenter(), new SizeD(20, 30));
            }

            Rectangle bounds = e.Bounds;
            Rectangle insets = Rectangle.FromLTRB(5, 5, 5, 25);

            Graphics      g       = e.Graphics;
            SmoothingMode oldMode = g.SmoothingMode;
            Region        oldClip = g.Clip;

            // in .net 3.5 there are repaint issues - none of the below seems to help, there
            // are still sometimes background rendering artifacts left over.
            g.IntersectClip(bounds);
            g.FillRegion(new SolidBrush(e.BackColor), g.Clip);
            g.Clear(e.BackColor);
            e.DrawBackground();

            var sx = (float)((bounds.Width - insets.Left - insets.Right) / node.Layout.Width);
            var sy = (float)((bounds.Height - insets.Top - insets.Bottom) / node.Layout.Height);

            if (sx > 0 && sy > 0)
            {
                var transform = g.Transform;
                g.SmoothingMode = SmoothingMode.HighQuality;

                g.TranslateTransform((float)(bounds.X + insets.Left), (float)(bounds.Y + insets.Top));
                g.ScaleTransform(Math.Min(sx, sy), Math.Min(sx, sy));
                g.TranslateTransform((float)(-node.Layout.X), (float)(-node.Layout.Y));

                //Get the renderer from the style, this requires the dummy node instance.
                var renderContext = new RenderContext(g, null)
                {
                    ViewTransform = g.Transform, WorldTransform = g.Transform
                };
                node.Style.Renderer.GetVisualCreator(node, node.Style).CreateVisual(renderContext).Paint(renderContext, g);
                var lgns = node.Style as LogicGateNodeStyle;
                if (lgns != null)
                {
                    g.DrawString(lgns.GateType.ToString(), new Font("Arial", 8.25f), Brushes.Black, -10, 20);
                }
                else if (node.Labels.Any())
                {
                    g.DrawString(node.Labels.First().Text.Replace("\n", " "), new Font("Arial", 8.25f), Brushes.Black, -10, 20);
                }
                g.Transform     = transform;
                g.SmoothingMode = oldMode;
            }

            g.Clip = oldClip;
            e.DrawFocusRectangle();
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            // get item text and image
            string     itemText  = Items[e.Index].ToString();
            IComboItem comboItem = (IComboItem)Items[e.Index];
            Image      itemImage = comboItem.Image;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected && Focused)
            {
                textColor = SystemColors.ControlText;
                backColor = Color.FromArgb(50, SystemColors.Highlight);
            }
            else
            {
                backColor = SystemColors.Window;
                textColor = SystemColors.ControlText;
            }
            Rectangle area = e.Bounds;

            //overlap issue in RTL builds in the selected box area ONLY
            if (area.X == 21)
            {
                area = ClientRectangle;
            }
            BidiGraphics g = new BidiGraphics(e.Graphics, area);

            // draw background (always paint white over it first)
            g.FillRectangle(Brushes.White, area);
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, area);

            // draw icon
            g.DrawImage(AllowMirroring, itemImage, area.Left + IMAGE_INSET, area.Top + area.Height / 2 - itemImage.Height / 2);

            // text format and drawing metrics
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter |
                                                   TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;
            int leftMargin = IMAGE_INSET + itemImage.Width + TEXT_INSET;

            // draw title line
            // post title
            int       titleWidth     = area.Right - leftMargin;
            Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height);

            g.DrawText(
                itemText,
                e.Font, titleRectangle, textColor, ellipsesStringFormat);

            // separator line if necessary
            if (!selected && DroppedDown)
            {
                using (Pen pen = new Pen(SystemColors.ControlLight))
                    g.DrawLine(pen, area.Left, area.Bottom - 1, area.Right, area.Bottom - 1);
            }

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }
            Rectangle area = e.Bounds;

            e.Graphics.ResetClip();

            BidiGraphics g = new BidiGraphics(e.Graphics, area);

            Image  borderImage = null;
            string borderText  = "";
            object item        = Items[e.Index];

            if (item != null)
            {
                borderText = item.ToString();
            }
            if (item is IComboImageItem)
            {
                IComboImageItem comboItem = (IComboImageItem)item;
                borderImage = comboItem.Image;
            }

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor = SystemColors.Window;
            Color textColor = SystemColors.ControlText;

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter |
                                                   TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, area);
            if (selected && Focused && dropDownShowing)
            {
                //draw the focus highlight rectangle
                Rectangle focusRect = new Rectangle(area.X, area.Y, area.Width - 1, area.Height - 1);
                using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, SystemColors.Highlight)))
                    g.FillRectangle(solidBrush, focusRect);
                using (Pen focusPen = new Pen(SystemColors.Highlight, 1))
                    g.DrawRectangle(focusPen, focusRect);
            }

            // draw border icon
            if (borderImage != null)
            {
                Rectangle imageRect =
                    new Rectangle(area.Left + HORIZONTAL_INSET, area.Top + TOP_INSET, borderImage.Width,
                                  borderImage.Height);
                g.DrawImage(false, borderImage, imageRect);
                //g.DrawRectangle(Pens.Blue, e.Bounds);
            }
            // calculate standard text drawing metrics
            int leftMargin = HORIZONTAL_INSET + MAX_IMAGE_WIDTH + HORIZONTAL_INSET;

            // draw title line
            // post title
            int       titleWidth     = e.Bounds.Width - leftMargin - 1;
            Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height - 1);

            //g.DrawRectangle(Pens.Red,titleRectangle);
            g.DrawText(
                borderText,
                e.Font, titleRectangle,
                textColor, ellipsesStringFormat);
            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
Beispiel #25
0
        private void PackageSourcesListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            var      currentListBox = (ListBox)sender;
            Graphics graphics       = e.Graphics;

            e.DrawBackground();

            if (e.Index < 0 ||
                e.Index >= currentListBox.Items.Count)
            {
                return;
            }

            var currentItem = (Configuration.PackageSource)currentListBox.Items[e.Index];

            using (StringFormat drawFormat = new StringFormat())
            {
                using (Brush foreBrush = new SolidBrush(currentListBox.SelectionMode == SelectionMode.None ? SystemColors.WindowText : e.ForeColor))
                {
                    drawFormat.Alignment     = StringAlignment.Near;
                    drawFormat.Trimming      = StringTrimming.EllipsisCharacter;
                    drawFormat.LineAlignment = StringAlignment.Near;
                    drawFormat.FormatFlags   = StringFormatFlags.NoWrap;

                    // the margin between the checkbox and the edge of the list box
                    const int edgeMargin = 8;
                    // the margin between the checkbox and the text
                    const int textMargin = 4;

                    // draw the enabled/disabled checkbox
                    CheckBoxState checkBoxState = currentItem.IsEnabled ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal;
                    Size          checkBoxSize  = CheckBoxRenderer.GetGlyphSize(graphics, checkBoxState);
                    CheckBoxRenderer.DrawCheckBox(
                        graphics,
                        new Point(edgeMargin, e.Bounds.Top + edgeMargin),
                        checkBoxState);

                    if (_checkBoxSize.IsEmpty)
                    {
                        // save the checkbox size so that we can detect mouse click on the
                        // checkbox in the MouseUp event handler.
                        // here we assume that all checkboxes have the same size, which is reasonable.
                        _checkBoxSize = checkBoxSize;
                    }

                    GraphicsState oldState = graphics.Save();
                    try
                    {
                        // turn on high quality text rendering mode
                        graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                        // draw each package source as
                        //
                        // [checkbox] Name
                        //            Source (italics)

                        int textWidth = e.Bounds.Width - checkBoxSize.Width - edgeMargin - textMargin;

                        SizeF nameSize = graphics.MeasureString(currentItem.Name, e.Font, textWidth, drawFormat);

                        // resize the bound rectangle to make room for the checkbox above
                        var nameBounds = new Rectangle(
                            e.Bounds.Left + checkBoxSize.Width + edgeMargin + textMargin,
                            e.Bounds.Top,
                            textWidth,
                            (int)nameSize.Height);

                        graphics.DrawString(currentItem.Name, e.Font, foreBrush, nameBounds, drawFormat);

                        var sourceBounds = new Rectangle(
                            nameBounds.Left,
                            nameBounds.Bottom,
                            textWidth,
                            e.Bounds.Bottom - nameBounds.Bottom);
                        graphics.DrawString(currentItem.Source, e.Font, foreBrush, sourceBounds, drawFormat);
                    }
                    finally
                    {
                        graphics.Restore(oldState);
                    }

                    // If the ListBox has focus, draw a focus rectangle around the selected item.
                    e.DrawFocusRectangle();
                }
            }
        }
Beispiel #26
0
        /// <summary>
        /// 代码树重绘事件
        /// </summary>
        private void codeListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            ListBox listBox = sender as ListBox;

            if (e.Index > -1)
            {
                string itemFull = listBox.Items[e.Index].ToString();
                string trimItem = itemFull.Trim().Split(' ')[0];
                Brush  FontBrush;
                if (trimItem.Length == 0)
                {
                    FontBrush = Brushes.Black;
                }
                else
                {
                    switch (trimItem.Substring(1))
                    {
                    case "角色状态":
                        FontBrush = Brushes.LightSlateGray;
                        break;

                    case "播放音乐":
                    case "播放声效":
                    case "播放BGS":
                    case "播放语音":
                        FontBrush = Brushes.MediumTurquoise;
                        break;

                    case "显示图片":
                    case "显示背景":
                    case "显示立绘":
                        FontBrush = Brushes.Violet;
                        break;

                    case "执行过渡":
                    case "动画":
                        FontBrush = Brushes.Plum;
                        break;

                    case "场景镜头":
                        FontBrush = Brushes.DeepSkyBlue;
                        break;

                    case "开关操作":
                    case "变量操作":
                        FontBrush = Brushes.Brown;
                        break;

                    case "标签":
                    case "标签跳转":
                        FontBrush = Brushes.Orange;
                        break;

                    case "注释":
                        FontBrush = Brushes.Green;
                        break;

                    case "循环":
                    case "以上反复":
                    case "中断循环":
                    case "条件分支":
                    case "除此以外的情况":
                    case "分支结束":
                        FontBrush = Brushes.Blue;
                        break;

                    case "代码片段":
                        FontBrush = Brushes.Gray;
                        break;

                    case "函数调用":
                    case "退出当前场景":
                    case "结束游戏":
                    case "返回标题":
                        FontBrush = Brushes.Purple;
                        break;

                    case "等待动画结束":
                    case "等待用户操作":
                    case "呼叫存档画面":
                    case "呼叫读档画面":
                    case "延时等待":
                        FontBrush = Brushes.OrangeRed;
                        break;

                    default:
                        FontBrush = Brushes.Black;
                        break;
                    }
                }
                e.DrawBackground();
                e.Graphics.DrawString(itemFull, e.Font, FontBrush, e.Bounds.Location);
                e.DrawFocusRectangle();
                this.codeListBox.HorizontalExtent = Math.Max(this.codeListBox.HorizontalExtent,
                                                             (int)e.Graphics.MeasureString(itemFull, e.Font).Width);
            }
        }
Beispiel #27
0
 private void DrawOnTab(object sender, DrawItemEventArgs e)
 {
     e.Graphics.DrawString("x", e.Font, Brushes.Black, e.Bounds.Right - 15, e.Bounds.Top + 4);
     e.Graphics.DrawString(this.tab_main.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + 12, e.Bounds.Top + 4);
     e.DrawFocusRectangle();
 }
Beispiel #28
0
        // Main paiting method
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            int maxItem = this.Items.Count - 1;

            if (e.Index < 0 || e.Index > maxItem)
            {
                // Erase all background if control has no items
                e.Graphics.FillRectangle(BackBrush, this.ClientRectangle);
                return;
            }

            int size = e.Font.Height; // button size depends on font height, not on item height

            // Calculate bounds for background, if last item paint up to bottom of control
            Rectangle backRect = e.Bounds;

            if (e.Index == maxItem)
            {
                backRect.Height = this.ClientRectangle.Top + this.ClientRectangle.Height - e.Bounds.Top;
            }

            // if selected, mark the background differently
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(SelectionBrush, e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(BackBrush, backRect);
            }

            // Determines text color/brush
            Brush textBrush;
            bool  isChecked = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            RadioButtonState state = isChecked ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal;

            if ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled)
            {
                textBrush = SystemBrushes.GrayText;
                state     = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled;
            }
            else if ((e.State & DrawItemState.Grayed) == DrawItemState.Grayed)
            {
                textBrush = SystemBrushes.GrayText;
                state     = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled;
            }
            else
            {
                textBrush = SystemBrushes.FromSystemColor(this.ForeColor);
            }

            // Determines bounds for text and radio button
            Size  glyphSize     = RadioButtonRenderer.GetGlyphSize(e.Graphics, state);
            Point glyphLocation = e.Bounds.Location;

            glyphLocation.Y += (e.Bounds.Height - glyphSize.Height) / 2;
            var       rightPadding = 5;
            Rectangle bounds       = new Rectangle(e.Bounds.X + glyphSize.Width + rightPadding, e.Bounds.Y, e.Bounds.Width - glyphSize.Width - rightPadding, e.Bounds.Height);

            // Draws the radio button
            RadioButtonRenderer.DrawRadioButton(e.Graphics, glyphLocation, state);

            // Draws the text
            if (!string.IsNullOrEmpty(DisplayMember)) // Bound Datatable? Then show the column written in Displaymember
            {
                e.Graphics.DrawString(((System.Data.DataRowView) this.Items[e.Index])[this.DisplayMember].ToString(),
                                      e.Font, textBrush, bounds, this.Align);
            }
            else
            {
                e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, textBrush, bounds, this.Align);
            }

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            ListBox    lb    = (ListBox)sender;
            Graphics   g     = e.Graphics;
            SolidBrush sback = new SolidBrush(e.BackColor);
            SolidBrush sfore = new SolidBrush(e.ForeColor);

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

            if (subnets.subnetslash % 4 == 0) //nibble
            {
                if (e.Index % 2 == 0)
                {
                    e.DrawBackground();
                    DrawItemState st = DrawItemState.Selected;

                    if ((e.State & st) != st)
                    {
                        g.FillRectangle(new SolidBrush(Color.WhiteSmoke), e.Bounds);
                        g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                     sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                    }
                    else
                    {
                        g.FillRectangle(sback, e.Bounds);
                        g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                     sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                    }
                    e.DrawFocusRectangle();
                }
                else
                {
                    e.DrawBackground();
                    g.FillRectangle(sback, e.Bounds);
                    g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                 sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                    e.DrawFocusRectangle();
                }
            }
            else //non-nible
            {
                int sayi = (1 << (4 - (subnets.subnetslash % 4)));

                if (sayi == 2)
                {
                    if (e.Index % 2 == 0)
                    {
                        e.DrawBackground();
                        DrawItemState st = DrawItemState.Selected;

                        if ((e.State & st) != st)
                        {
                            g.FillRectangle(new SolidBrush(Color.WhiteSmoke), e.Bounds);
                            g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                         sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        }
                        else
                        {
                            g.FillRectangle(sback, e.Bounds);
                            g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                         sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        }
                        e.DrawFocusRectangle();
                    }
                    else
                    {
                        e.DrawBackground();
                        g.FillRectangle(sback, e.Bounds);
                        g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                     sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        e.DrawFocusRectangle();
                    }
                }
                else if (sayi == 4)
                {
                    if (e.Index % 4 == 0)
                    {
                        e.DrawBackground();
                        DrawItemState st = DrawItemState.Selected;

                        if ((e.State & st) != st)
                        {
                            g.FillRectangle(new SolidBrush(Color.WhiteSmoke), e.Bounds);
                            g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                         sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        }
                        else
                        {
                            g.FillRectangle(sback, e.Bounds);
                            g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                         sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        }
                        e.DrawFocusRectangle();
                    }
                    else
                    {
                        e.DrawBackground();
                        g.FillRectangle(sback, e.Bounds);
                        g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                     sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        e.DrawFocusRectangle();
                    }
                }
                else if (sayi == 8)
                {
                    if (e.Index % 8 == 0)
                    {
                        e.DrawBackground();
                        DrawItemState st = DrawItemState.Selected;

                        if ((e.State & st) != st)
                        {
                            g.FillRectangle(new SolidBrush(Color.WhiteSmoke), e.Bounds);
                            g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                         sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        }
                        else
                        {
                            g.FillRectangle(sback, e.Bounds);
                            g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                         sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        }
                        e.DrawFocusRectangle();
                    }
                    else
                    {
                        e.DrawBackground();
                        g.FillRectangle(sback, e.Bounds);
                        g.DrawString(lb.Items[e.Index].ToString(), e.Font,
                                     sfore, new PointF(e.Bounds.X, e.Bounds.Y));
                        e.DrawFocusRectangle();
                    }
                }
            }

            // Last item is the widest one due to its index but may not be depending on the font-width
            // e.g., '0' and 'f' does not have he same width if the font is not fixed-width.
            // ps: Try to use Fixed-width Font if available.

            lb.HorizontalScrollbar = true;
            int horzSize = (int)g.MeasureString(lb.Items[e.Index].ToString(), lb.Font).Width;

            if (horzSize > maxfontwidth)
            {
                maxfontwidth        = horzSize;
                lb.HorizontalExtent = maxfontwidth;
            }
        }
	/// <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();
				}
			}
		}
	}
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            bool isItemTitle = false;
            bool isItemStep  = false;
            bool isItemParam = false;
            bool isItemCheck = false;

            if (listBox1.Items.Count != 0)
            {
                isItemTitle = (listBox1.GetItemText(listBox1.Items[e.Index]).Contains("Case:")) ? true : false;
                isItemStep  = (listBox1.GetItemText(listBox1.Items[e.Index]).Contains("Step:")) ? true : false;
                isItemParam = (listBox1.GetItemText(listBox1.Items[e.Index]).Contains("Param:")) ? true : false;
                isItemCheck = (listBox1.GetItemText(listBox1.Items[e.Index]).Contains("Check:")) ? true : false;
            }

            bool isItemSelected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);
            int  itemIndex      = e.Index;

            if (itemIndex >= 0 && itemIndex < listBox1.Items.Count)
            {
                Color    c = new Color();
                Graphics g = e.Graphics;
                if (isItemSelected)
                {
                    c = Color.DarkRed;
                    int d = e.Index;
                    while (d >= 0)
                    {
                        if (listBox1.GetItemText(listBox1.Items[d]).Contains("Case:"))
                        {
                            foreach (Case h in testCases)
                            {
                                h.selected = false;
                            }
                            testCases.Find(t => t.name.Trim() == listBox1.GetItemText(listBox1.Items[d]).Split(':')[1].Trim()).selected = true;
                            d = -1;
                        }
                        d--;
                    }
                }
                else if (isItemTitle)
                {
                    c = ColorTranslator.FromHtml("#199cff");
                }
                else if (isItemStep)
                {
                    c = ColorTranslator.FromHtml("#59b8ff");
                }
                else if (isItemParam)
                {
                    //#a3d6fd
                    c = Color.LightSkyBlue;
                }
                else if (isItemCheck)
                {
                    c = Color.Orange;
                }

                // Background Color
                SolidBrush backgroundColorBrush = new SolidBrush(c);

                g.FillRectangle(backgroundColorBrush, e.Bounds);

                // Set text color
                string itemText = listBox1.Items[itemIndex].ToString();

                SolidBrush itemTextColorBrush = (c != Color.White) ? new SolidBrush(Color.White) : new SolidBrush(Color.Black);
                g.DrawString(itemText, e.Font, itemTextColorBrush, listBox1.GetItemRectangle(itemIndex).Location);

                // Clean up
                backgroundColorBrush.Dispose();
                itemTextColorBrush.Dispose();
            }

            e.DrawFocusRectangle();
        }
Beispiel #32
0
        /// <summary>
        /// Zeichnet den Item der Combobox
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // Hintergrund zeichnen
            e.DrawBackground();
            e.DrawFocusRectangle();

            // Überprüfen ob der Item zu der Auflistung gehört
            if (e.Index < 0)
            {
                int imgSizeWidth = 0;
                if (imgs != null)
                {
                    imgSizeWidth = imgs.ImageSize.Width;
                }

                e.Graphics.DrawString(this.Text, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + imgSizeWidth, e.Bounds.Top);
            }
            else
            {
                if (this.Items != null)
                {
                    // Überprüfen sich bei dem Item um ein ImageTextComboItem handelt
                    if (this.Items[e.Index].GetType() == typeof(ImageTextComboItem))
                    {
                        // Item laden
                        ImageTextComboItem item = (ImageTextComboItem)this.Items[e.Index];

                        // Schrift und Farbe laden
                        Color forecolor = (item.ForeColor != Color.FromKnownColor(KnownColor.Transparent)) ? item.ForeColor : e.ForeColor;
                        Font  font      = item.Mark ? new Font(e.Font, FontStyle.Bold) : e.Font;

                        // -1: wenn der Item kein Bild enthält
                        if (item.ImageIndex != -1)
                        {
                            try
                            {
                                // Falls der Item ein Bild enthält, wird dieses aus der Imagelist geladen und neben dem Text gezeichnet
                                if (this.ImageList != null)
                                {
                                    this.ImageList.Draw(e.Graphics, e.Bounds.Left, e.Bounds.Top, item.ImageIndex);
                                }
                            }
                            catch
                            { }

                            e.Graphics.DrawString(item.Text, font, new SolidBrush(forecolor), e.Bounds.Left + imgs.ImageSize.Width, e.Bounds.Top);
                        }
                        else
                        {
                            // Falls kein Bild vorhanden ist, dann wird nur der Text gezeichnet
                            e.Graphics.DrawString(item.Text, font, new SolidBrush(forecolor), e.Bounds.Left + imgs.ImageSize.Width, e.Bounds.Top);
                        }
                    }
                    else
                    {
                        // Wenn es kein ImageTextComboItem ist dann wird nur Text dargestellt
                        e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + imgs.ImageSize.Width, e.Bounds.Top);
                    }
                }
            }

            base.OnDrawItem(e);
        }
Beispiel #33
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            // get post we are rendering
            PostInfo postInfo = (Items[e.Index] as PostInfoItem).PostInfo;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.NoPrefix;

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            // draw top-line if necessary
            //if ( !selected )
            {
                using (Pen pen = new Pen(_theme.topLineColor))
                    g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - ScaleY(1));
            }

            // draw post icon
            g.DrawImage(false, _blogPostImage, new Rectangle(
                            e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(TITLE_INSET),
                            ScaleX(_blogPostImage.Width), ScaleY(_blogPostImage.Height)));

            // calculate standard text drawing metrics
            int leftMargin = ScaleX(HORIZONTAL_INSET) + ScaleX(_blogPostImage.Width) + ScaleX(HORIZONTAL_INSET);
            int topMargin  = e.Bounds.Top + ScaleY(TITLE_INSET);
            // draw title line

            // post date
            string    dateText      = postInfo.PrettyDateDisplay;
            Size      dateSize      = g.MeasureText(dateText, e.Font);
            Rectangle dateRectangle = new Rectangle(
                e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - dateSize.Width, topMargin, dateSize.Width, dateSize.Height);

            g.DrawText(dateText, e.Font, dateRectangle, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix);

            // post title
            int       titleWidth     = dateRectangle.Left - leftMargin - ScaleX(DATE_PADDING);
            string    titleString    = String.Format(CultureInfo.CurrentCulture, "{0}", postInfo.Title);
            int       fontHeight     = g.MeasureText(titleString, e.Font).Height;
            Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight);

            g.DrawText(
                titleString,
                e.Font,
                titleRectangle, textColor, ellipsesStringFormat);

            // draw post preview

            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                leftMargin,
                topMargin + fontHeight + ScaleY(PREVIEW_INSET),
                e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET),
                fontHeight * PREVIEW_LINES);

            // draw post preview
            string postPreview = postInfo.PlainTextContents;

            if (PostSource.HasMultipleWeblogs && (postInfo.BlogName != String.Empty))
            {
                postPreview = String.Format(CultureInfo.CurrentCulture, "{0} - {1}", postInfo.BlogName, postPreview);
            }

            g.DrawText(
                postPreview,
                e.Font, layoutRectangle, textColor, ellipsesStringFormat);

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
Beispiel #34
0
        ///// <summary>
        ///// The main entry point for the application.
        ///// </summary>
        //[STAThread]
        //static void Main()
        //{
        //    Application.Run(new FrmColorListBox());

        //}

        private void DrawItemHandler(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            e.Graphics.DrawString(data[e.Index], new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold), new SolidBrush(color[e.Index]), e.Bounds);
        }