当前位置: 首页>>代码示例>>C#>>正文


C# DrawItemEventArgs.DrawBackground方法代码示例

本文整理汇总了C#中System.Windows.Forms.DrawItemEventArgs.DrawBackground方法的典型用法代码示例。如果您正苦于以下问题:C# DrawItemEventArgs.DrawBackground方法的具体用法?C# DrawItemEventArgs.DrawBackground怎么用?C# DrawItemEventArgs.DrawBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.DrawItemEventArgs的用法示例。


在下文中一共展示了DrawItemEventArgs.DrawBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnDrawItem

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            if (e.Index >= 0 && e.Index < Items.Count)
            {
                Device dev = (Device)Items[e.Index];
                Image image = ImageList.Images[dev.ImageKey];
                image = ResizeImage(image, 48, 48);

                Rectangle r = e.Bounds;
                r.Size = image.Size;
                r.X += 2;
                r.Y += (e.Bounds.Height - r.Height) / 2;
                e.Graphics.DrawImageUnscaled(image, r);

                r = e.Bounds;
                r.X += image.Width + 2;
                r.Width -= image.Width + 2;
                using (StringFormat sf = new StringFormat())
                {
                    sf.LineAlignment = StringAlignment.Center;
                    e.Graphics.DrawString(dev.Name, Font, new SolidBrush(ForeColor), r, sf);
                }
            }
            base.OnDrawItem(e);
        }
开发者ID:ndkimhao,项目名称:EnergyMeshApp-WinForm,代码行数:27,代码来源:CustomControl.cs

示例2: OnDrawItem

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;
            Rectangle area = e.Bounds;
            Rectangle iconArea = area;
            iconArea.Width = 16;
            if (e.Index >= 0)
            {
                e.DrawBackground();
                Entity ent = (Entity)Items[e.Index];
                int dist = (int)Vector3i.Distance(ent.Pos, PlayerPos);

                // Draw entity icon
                g.DrawImage(ent.Image, iconArea);

                // Entity name
                SizeF entName = g.MeasureString(ent.ToString(), this.Font);
                Rectangle ctxt = area;
                ctxt.X = iconArea.Right + 3;
                ctxt.Width = (int)entName.Width + 1;
                g.DrawString(ent.ToString(), this.Font, new SolidBrush(e.ForeColor), ctxt);

                // Distance.
                string derp = string.Format("({0}m away)", dist);
                SizeF entDist = g.MeasureString(derp, this.Font);
                Rectangle distArea = area;
                distArea.X = ctxt.Right + 3;
                distArea.Width = (int)entDist.Width;
                g.DrawString(derp, this.Font, new SolidBrush(Color.FromArgb(128, e.ForeColor)), distArea);
            }
        }
开发者ID:herpit,项目名称:MineEdit,代码行数:31,代码来源:EntitySelector.cs

示例3: OnDrawItem

  protected override void OnDrawItem( DrawItemEventArgs e )
  {
   e.DrawBackground();
   e.DrawFocusRectangle();

   if( e.Index > -1 )
   {
    ComboBoxItem itm = (( ComboBoxItem ) Items[ e.Index ]);
    int x = e.Bounds.Left + ( 16 - itm.Img.Width ) / 2,
        y = ( 15 - itm.Img.Height ) / 2,
        w = itm.Img.Width,
        h = itm.Img.Height;

    x = ( x > 0 ) ? x : 0;
    y = (( y > 0 ) ? y : 0 ) + e.Bounds.Top;
    w = ( w > 15 ) ? 15 : w;
    h = ( h > 15 ) ? 15 : h;

    e.Graphics.DrawImage( itm.Img,
                          new Rectangle( x, y, w, h ),
                          new Rectangle( 0, 0, itm.Img.Width, itm.Img.Height ),
                          GraphicsUnit.Pixel );
    e.Graphics.DrawString( itm.Text,
                           e.Font,
                           new SolidBrush( e.ForeColor ),
                           x + w,
                           e.Bounds.Top + 2 );

   }

   base.OnDrawItem( e );

  }
开发者ID:InTheSPOT,项目名称:creative-mode-plus,代码行数:33,代码来源:ComboBoxWithIcons.cs

示例4: OnDrawItem

        /// <summary>
        /// Owner drawing listview item.
        /// </summary>
        protected void OnDrawItem( DrawItemEventArgs e, PluginListItem item )
        {
            e.DrawBackground();

            // IsRunnning bitmap
            const int imageWidth = 16+3;
            if(imageList==null)
                imageList = ((PluginDialog)Parent).ImageList;
            if(imageList!=null)
            {
                int imageIndex = item.PluginInfo.IsCurrentlyLoaded ? 0 : 1;
                imageList.Draw(e.Graphics, e.Bounds.Left+2, e.Bounds.Top+1, imageIndex);
            }

            // Name
            Rectangle bounds = Rectangle.FromLTRB(e.Bounds.Left+imageWidth,
                e.Bounds.Top, e.Bounds.Left+Columns[0].Width, e.Bounds.Bottom);
            using(Brush brush = new SolidBrush(e.ForeColor))
                e.Graphics.DrawString(item.Name, e.Font, brush, bounds);

            // Check box (Load at startup)
            bounds = Rectangle.FromLTRB(bounds.Right+1,
                bounds.Top, bounds.Right+Columns[1].Width+1, bounds.Bottom-1);
            ButtonState state = item.PluginInfo.IsLoadedAtStartup ? ButtonState.Checked : ButtonState.Normal;
            ControlPaint.DrawCheckBox(e.Graphics, bounds, state);
        }
开发者ID:paladin74,项目名称:Dapple,代码行数:29,代码来源:PluginListView.cs

示例5: OnDrawItem

        protected override void OnDrawItem(DrawItemEventArgs ea)
        {
            ea.DrawBackground();
            ea.DrawFocusRectangle();

            if (ea.Index == -1)
                return;

            Rectangle bounds = ea.Bounds;
            var foreBrush = new SolidBrush(ea.ForeColor);
            int textLeftBound = (IconList == null) ? bounds.Left : bounds.Left + IconList.ImageSize.Width;

            var drawObject = Items[ea.Index];
            if (drawObject is ImageComboBoxItem) {
                var drawItem = (ImageComboBoxItem)drawObject;

                if (drawItem.ImageListIndex != -1 && IconList != null) {
                    //ea.Graphics.FillRectangle(Brushes.Gray, bounds.Left, bounds.Top, IconList.ImageSize.Width, IconList.ImageSize.Height);
                    ea.Graphics.DrawImage(IconList.Images[drawItem.ImageListIndex], bounds.Left, bounds.Top);
                }

                ea.Graphics.DrawString(drawItem.Text, ea.Font, foreBrush, textLeftBound, bounds.Top);
            }
            else {
                ea.Graphics.DrawString(drawObject.ToString(), ea.Font, foreBrush, textLeftBound, bounds.Top);
            }

            base.OnDrawItem(ea);
        }
开发者ID:samerai,项目名称:preseria-preview,代码行数:29,代码来源:ImageComboBox.cs

示例6: lstFunnel_DrawItem

 private void lstFunnel_DrawItem(object sender, DrawItemEventArgs e)
 {
     dontRefresh = true;
     e.DrawBackground();
     FontStyle fs = FontStyle.Regular;
     Brush b = Brushes.Black;
     if (unselectableFunnelLines.Contains(e.Index))
     {
         b = Brushes.Gray;
         fs = FontStyle.Italic;
         if (e.State.HasFlag(DrawItemState.Selected))
         {
             //b = Brushes.White;
             lstFunnel.SelectedIndex = -1;
             lstFunnel.Invalidate();
         }
         e.Graphics.DrawString(lstFunnel.Items[e.Index].ToString(), new Font("Microsoft Sans Serif", 8, fs), b, e.Bounds);
     }
     else
     {
         if (e.State.HasFlag(DrawItemState.Selected)) b = Brushes.White;
         e.Graphics.DrawString(lstFunnel.Items[e.Index].ToString(), new Font("Microsoft Sans Serif", 8, fs), b, e.Bounds);
         e.DrawFocusRectangle();
     }
     dontRefresh = false;
 }
开发者ID:emote-project,项目名称:Scenario1,代码行数:26,代码来源:frmConflictResolution.cs

示例7: SecurityCB_DrawItem

        private void SecurityCB_DrawItem(object sender, DrawItemEventArgs e)
        {
            // If the index is invalid then simply exit.
            if (e.Index == -1 || e.Index >= SecurityCB.Items.Count)
            {
                return;
            }

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

            // Should we draw the focus rectangle?
            if ((e.State & DrawItemState.Focus) != 0)
            {
                e.DrawFocusRectangle();
            }

            Font f = new Font(e.Font, FontStyle.Regular);
            // Create a new background brush.
            Brush b = new SolidBrush(e.ForeColor);
            // Draw the item.
            Security security = (Security)SecurityCB.Items[e.Index];
            string name = security.ToString();
            SizeF s = e.Graphics.MeasureString(name, f);
            e.Graphics.DrawString(name, f, b, e.Bounds);
        }
开发者ID:tomasfrizu,项目名称:GXDLMSDirector,代码行数:26,代码来源:AuthenticationGmacForm.cs

示例8: drawItems

        private void drawItems(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();

            int i = e.Index;
            if (i != -1)
            {

                Font myFont;
                Brush myBrush;
                string dir = currentDir + "\\" + MovieBox.Items[i];

                string[] content = Directory.GetFiles(dir, "*.nfo", SearchOption.TopDirectoryOnly);
                if (content.Length == 0 && i != 0)
                {
                    myFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold);
                    myBrush = Brushes.Red;
                }
                else
                {
                    myFont = e.Font;
                    myBrush = Brushes.Black;
                }

                e.Graphics.DrawString(MovieBox.Items[i].ToString(), myFont, myBrush, e.Bounds, StringFormat.GenericDefault);
            }
        }
开发者ID:ahglas,项目名称:Movieorganizer,代码行数:27,代码来源:Form1.cs

示例9: OnDrawItem

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();

            if (e.Index < 0)
                return;

            FontFamily fontFamily = Items[e.Index] as FontFamily;

            if ((e.State & DrawItemState.ComboBoxEdit) != 0)
            {
                Font font = e.Font;
                if (DrawFontInEditBox)
                {
                    if (!fontsInCache)
                    {
                        font = CreateDefaultFont(fontFamily, e.Font.Size);
                        if (font == null)
                            font = e.Font;
                    }
                    else
                    {
                        font = fonts[fontFamily.Name];
                        if (font == null)
                            font = e.Font;
                    }
                }

                e.Graphics.DrawString(fontFamily.Name, font, new SolidBrush(e.ForeColor),
                    e.Bounds.Left, e.Bounds.Top);
            }
            else
            {
                Font font = e.Font;
                if (DrawFont)
                {
                    if (!fontsInCache)
                    {
                        font = CreateDefaultFont(fontFamily, e.Font.Size);
                        if (font == null)
                            font = e.Font;
                    }
                    else
                    {
                        font = fonts[fontFamily.Name];
                        if (font == null)
                            font = e.Font;
                    }
                }

                e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
                e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                e.Graphics.DrawString(fontFamily.Name, font, new SolidBrush(e.ForeColor),
                    e.Bounds.Left, e.Bounds.Top);
            }
        }
开发者ID:CHiiLD,项目名称:net-toolkit,代码行数:60,代码来源:FontPaintComboBox.cs

示例10: OnDrawItem

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();

            if (Items.Count <= 0)
            {
                base.OnDrawItem(e);
                return;
            }

            Color color;

            color = ColorGetter == null ? SystemColors.WindowText
                    : ColorGetter(e.Index, Items[e.Index]);

            if(color == SystemColors.WindowText
                && ((e.State & DrawItemState.Selected) == DrawItemState.Selected))
                color = SystemColors.HighlightText;

            using (Brush b = new SolidBrush(color))
            {
                e.Graphics.DrawString(Convert.ToString(Items[e.Index]), e.Font, b, e.Bounds);
            }

            if((e.State & DrawItemState.Focus) == DrawItemState.Focus)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
            }
        }
开发者ID:devfinity-fx,项目名称:cpms_z,代码行数:29,代码来源:ColoredListBox.cs

示例11: OnDrawItem

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index >= 0 && e.Index < Items.Count)
            {
                this.ItemHeight = newItemHeight;
                Window window = Items[e.Index] as Window;
                String title = window.getTitle().Replace("&", "&&");
                String processName = window.getProcessName().Replace("&", "&&");

                e.DrawBackground();

                // Draw icon
                Icon icon = window.getIcon();
                if (icon != null)
                {
                    Image image = (Image)new Bitmap(icon.ToBitmap(), new Size(iconSize, iconSize));
                    e.Graphics.DrawImage(image, iconMargin, e.Bounds.Y + iconMargin);
                }

                // Draw window title
                Rectangle titleRect = e.Bounds;
                titleRect.Height /= 2;
                titleRect.X += iconSize + 3 * iconMargin;
                titleRect.Width -= iconSize + 3 * iconMargin;
                TextRenderer.DrawText(e.Graphics, title, titleFont, titleRect, e.ForeColor, titleFlags);

                // Draw process name title
                Rectangle processRect = titleRect;
                processRect.Y += processRect.Height;
                TextRenderer.DrawText(e.Graphics, processName, processFont, processRect, processColor, processFlags);
                e.DrawFocusRectangle();
            }
        }
开发者ID:guija,项目名称:sprung,代码行数:33,代码来源:WindowListBox.cs

示例12: settings2_3_booknamefont_DrawItem

        private void settings2_3_booknamefont_DrawItem(object sender, DrawItemEventArgs e)
        {
            Font objFonts = new Font(settings2_3_booknamefont.Items[e.Index].ToString(), 14);
            e.DrawBackground();

            e.Graphics.DrawString(settings2_3_booknamefont.Items[e.Index].ToString(), objFonts, new SolidBrush(e.ForeColor), new Point(e.Bounds.Left, e.Bounds.Top));
        }
开发者ID:henryxrl,项目名称:SimpleEpub2,代码行数:7,代码来源:Settings_Page2.cs

示例13: comboBoxColor_DrawItem

 private void comboBoxColor_DrawItem(object sender, DrawItemEventArgs e)
 {
     var box = (ComboBox) sender;
     if ((e.State & DrawItemState.Selected) != DrawItemState.None) {
         e.DrawBackground();
     }
     else {
         e.Graphics.FillRectangle(Brushes.White, e.Bounds);
     }
     if ((e.State & DrawItemState.Focus) != DrawItemState.None) {
         e.DrawFocusRectangle();
     }
     if (e.Index == 0) {
         e.Graphics.DrawString(box.Items[e.Index].ToString(), box.Font, Brushes.Black, e.Bounds);
     }
     else if ((e.Index >= 0) && (e.Index < box.Items.Count)) {
         var bounds = e.Bounds;
         bounds.Inflate(-16, -2);
         var boxItems = box.Items[e.Index] as string;
         if (boxItems == null) {
             return;
         }
         using (var brush = new SolidBrush(Color.FromArgb(int.Parse(boxItems.Substring(1))))) {
             e.Graphics.FillRectangle(brush, bounds);
             e.Graphics.DrawRectangle(Pens.Black, bounds);
         }
     }
 }
开发者ID:jmcadams,项目名称:vplus,代码行数:28,代码来源:CurveLibraryDialog.cs

示例14: OnDrawItem

        protected override void OnDrawItem( DrawItemEventArgs e )
        {
            if ( Items.Count == 0 )
            {
                base.OnDrawItem( e );
                return;
            }

            if ( Items[ e.Index ] is Friend )
            {
                Friend friendObj = ( Friend )Items[ e.Index ];

                this.DrawMode = DrawMode.OwnerDrawFixed;

                e.DrawBackground();

                e.DrawFocusRectangle();

                EPersonaState state = SteamContext.SteamFriends.GetFriendPersonaState( friendObj.SteamID );

                if ( state == EPersonaState.k_EPersonaStateOffline )
                    e.Graphics.DrawString( friendObj.PersonaName, e.Font, new SolidBrush( Color.Red ), e.Bounds );
                else
                    e.Graphics.DrawString( friendObj.PersonaName, e.Font, new SolidBrush( Color.Green ), e.Bounds );
            }
        }
开发者ID:AluminumKen,项目名称:hl2sb-src,代码行数:26,代码来源:FriendList.cs

示例15: OnDrawItem

    // Draw list item
    protected void OnDrawItem(object sender, DrawItemEventArgs e)
    {
      if (e.Index >= 0)
      {
        // Get this color
        ColorInfo color = (ColorInfo)Items[e.Index];

        // Fill background
        e.DrawBackground();

        // Draw color box
        Rectangle rect = new Rectangle();
        rect.X = e.Bounds.X + 2;
        rect.Y = e.Bounds.Y + 2;
        rect.Width = 18;
        rect.Height = e.Bounds.Height - 5;
        e.Graphics.FillRectangle(new SolidBrush(color.Color), rect);
        e.Graphics.DrawRectangle(SystemPens.WindowText, rect);

        // Write color name
        Brush brush;
        if ((e.State & DrawItemState.Selected) != DrawItemState.None)
          brush = SystemBrushes.HighlightText;
        else
          brush = SystemBrushes.WindowText;
        e.Graphics.DrawString(color.Text, Font, brush,
            e.Bounds.X + rect.X + rect.Width + 2,
            e.Bounds.Y + ((e.Bounds.Height - Font.Height) / 2));

        // Draw the focus rectangle if appropriate
        if ((e.State & DrawItemState.NoFocusRect) == DrawItemState.None)
          e.DrawFocusRectangle();
      }
    }
开发者ID:aluxnimm,项目名称:outlookcaldavsynchronizer,代码行数:35,代码来源:ColorPicker.cs


注:本文中的System.Windows.Forms.DrawItemEventArgs.DrawBackground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。