private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e) { if (G_ImageList != null)//判断ImageList是否为空 { Graphics g = e.Graphics;//得到绘图对象 Rectangle r = e.Bounds;//得到绘图范围 Size imageSize = G_ImageList.ImageSize;//获取图像大小 if (e.Index >= 0)//判断是否有绘制项 { Font fn = new Font("宋体", 10, FontStyle.Bold);//创建字体对象 string s = cbox_DisplayPictures.Items[e.Index].ToString();//得到绘制项的字符串 DrawItemState dis = e.State; if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect)) { e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r);//画条目背景 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串 r.Left + imageSize.Width, r.Top); e.DrawFocusRectangle();//显示取得焦点时的虚线框 } else { e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r);//画条目背景 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串 r.Left + imageSize.Width, r.Top); e.DrawFocusRectangle();//显示取得焦点时的虚线框 } } } }
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); } }
protected override void OnDrawItem( DrawItemEventArgs e ) { base.OnDrawItem( e ); if ( e.Index != -1 ) { object item = Items[e.Index]; e.DrawBackground(); e.DrawFocusRectangle(); bool separator = item is SeparatorItem; Rectangle bounds = e.Bounds; bool drawSeparator = separator && ( e.State & DrawItemState.ComboBoxEdit ) != DrawItemState.ComboBoxEdit; if ( drawSeparator ) { bounds.Height -= separatorHeight; } TextRenderer.DrawText( e.Graphics, GetDisplayText( e.Index ), Font, bounds, e.ForeColor, e.BackColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter ); if ( drawSeparator ) { Rectangle sepRect = new Rectangle( e.Bounds.Left, e.Bounds.Bottom - separatorHeight, e.Bounds.Width, separatorHeight ); using ( Brush b = new SolidBrush( BackColor ) ) { e.Graphics.FillRectangle( b, sepRect ); } e.Graphics.DrawLine( SystemPens.ControlText, sepRect.Left + 2, sepRect.Top + 1, sepRect.Right - 2, sepRect.Top + 1 ); } } }
protected override void OnDrawItem(DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); try { Image image = (Image)this.Items[e.Index]; Rectangle rec = e.Bounds; rec.Height -= 2; rec.Width -= 2; rec.X += 1; rec.Y += 1; e.Graphics.DrawImage(image, rec); } catch { if (e.Index != -1) { //不是图片则显示字符 e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y); } } finally { base.OnDrawItem(e); } }
private void annotationListBox_DrawItem( object sender, DrawItemEventArgs e ) { e.DrawBackground(); AnnotationListItem item = (AnnotationListItem) annotationListBox.Items[e.Index]; e.Graphics.DrawString( item.annotation.Point.ToString("f3"), annotationListBox.Font, new SolidBrush( annotationListBox.ForeColor ), new PointF( (float) e.Bounds.X, (float) e.Bounds.Y ) ); string label; if( item.annotation.Label.Contains(" ") ) label = "\"" + item.annotation.Label + "\""; else label = item.annotation.Label; e.Graphics.DrawString( label, annotationListBox.Font, new SolidBrush( annotationListBox.ForeColor ), new PointF( (float) e.Bounds.X + ( ( e.Bounds.Width / 2 ) - ( e.Bounds.Height * 2 ) ), (float) e.Bounds.Y ) ); Rectangle colorSampleBox = new Rectangle( e.Bounds.Location, e.Bounds.Size ); colorSampleBox.X = e.Bounds.Right - e.Bounds.Height * 2; colorSampleBox.Location.Offset( -5, 0 ); e.Graphics.FillRectangle( new SolidBrush( ownerGraphForm.ZedGraphControl.GraphPane.Chart.Fill.Color ), colorSampleBox ); int middle = colorSampleBox.Y + colorSampleBox.Height / 2; e.Graphics.DrawLine( new Pen( item.annotation.Color, item.annotation.Width ), colorSampleBox.Left, middle, colorSampleBox.Right, middle ); e.DrawFocusRectangle(); }
void ColorComboBox_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); if (e.Index >= 0) { Rectangle rectangle = new Rectangle(4, e.Bounds.Top + 2, 30, e.Bounds.Height - 4); Color rectColor = (Color)Items[e.Index]; e.Graphics.FillRectangle(new SolidBrush(rectColor), rectangle); e.Graphics.DrawRectangle(System.Drawing.Pens.Black, rectangle); if (e.Index == 0) { e.Graphics.DrawString("Custom", e.Font, System.Drawing.Brushes.Black, new PointF(42, e.Bounds.Top + 2)); } else { e.Graphics.DrawString(((Color)Items[e.Index]).Name, e.Font, System.Drawing.Brushes.Black, new PointF(42, e.Bounds.Top + 2)); } if (!Enabled) { HatchBrush brush = new HatchBrush(HatchStyle.Percent50, Color.LightGray, Color.FromArgb(10, Color.LightGray)); rectangle.Inflate(1, 1); e.Graphics.FillRectangle(brush, rectangle); brush.Dispose(); } e.DrawFocusRectangle(); } }
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); }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index < 0 || e.Index >= this.Items.Count) return; //e.DrawBackground(); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { LinearGradientBrush brush = new LinearGradientBrush(new Point(e.Bounds.X, e.Bounds.Y), new Point(e.Bounds.X, e.Bounds.Bottom), Color.AliceBlue, Color.LightSkyBlue); e.Graphics.FillRectangle(brush, e.Bounds); } else e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); e.DrawFocusRectangle(); ClipboardItem ci = (ClipboardItem)this.Items[e.Index]; /*e.Graphics.DrawString(ci.Name, this.Font, Brushes.Black, new PointF(2 + e.Bounds.X, 2 + e.Bounds.Y)); e.Graphics.DrawString(ci.AddtionalInfo, this.AddtionalInfoFont, Brushes.Gray, new PointF(2 + e.Bounds.X, 15 + e.Bounds.Y));*/ TextRenderer.DrawText(e.Graphics, ci.Name, this.Font, e.Bounds, Color.Black, Color.Transparent, TextFormatFlags.Top | TextFormatFlags.Left | TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine); TextRenderer.DrawText(e.Graphics, ci.AddtionalInfo, this.AddtionalInfoFont, e.Bounds, Color.Gray, Color.Transparent, TextFormatFlags.Bottom | TextFormatFlags.Left); base.OnDrawItem(e); }
private void xxcbDrawItem(object sender, DrawItemEventArgs e) { //drawItems here if (sender == null) return; if (e.Index < 0) return; //Get the Combo from the sender object ComboBox cbo = (ComboBox)sender; //Get the FontFamily from put in constructor FontFamily ff = new FontFamily(cbo.Items[e.Index].ToString()); //Set font style FontStyle fs = FontStyle.Regular; if (!ff.IsStyleAvailable(fs)) fs = FontStyle.Italic; if (!ff.IsStyleAvailable(fs)) fs = FontStyle.Bold; //Set font for drawing with (wich is the font itself) Font font = new Font(ff, 8, fs); //draw the background and focus rectangle e.DrawBackground(); e.DrawFocusRectangle(); //get graphics Graphics g = e.Graphics; //And draw with whatever font and brush we wish g.DrawString(font.Name, font, Brushes.ForestGreen, e.Bounds.X, e.Bounds.Y); }
/// <summary> /// This method will draw the items of the DropDownList. It will draw the Icon and the text and /// with the indent that goes with the item /// </summary> void ComboBox_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) return; else { BrowserComboItem item = (BrowserComboItem)Items[e.Index]; e.DrawBackground(); e.DrawFocusRectangle(); int indentOffset = indentWidth * item.Indent; int imageYOffset = (e.Bounds.Height - item.Image.Height) / 2; Point imagePoint = new Point( e.Bounds.Left + indentOffset + 2, e.Bounds.Top + imageYOffset); Size textSize = e.Graphics.MeasureString(item.Text, Font).ToSize(); int textYOffset = (e.Bounds.Height - textSize.Height) / 2; Point textPoint = new Point( e.Bounds.Left + item.Image.Width + indentOffset + 2, e.Bounds.Top + textYOffset); e.Graphics.DrawIcon(item.Image, imagePoint.X, imagePoint.Y); e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), textPoint); } }
/// <summary> /// Custom Draw Item Handler. /// It fires when painting each item in dropdown list. We use item value (text) to create the path to picture in resource and paint it in the list. /// </summary> /// <param name="e">Arguments from DrawItem Event</param> protected override void OnDrawItem(DrawItemEventArgs e) { // Draw background and focus rectangle, if necessary. e.DrawBackground(); e.DrawFocusRectangle(); // If something is selected, paint it if (e.Index > -1) { // Get text from current item var text = (string)Items[e.Index]; // Get resource path to picture var resource = string.Format("HSCardGenerator.Resources.Images.Flags.{0}.png", text.ToLower()); // Read it as stream using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource)) { // And paint it e.Graphics.DrawImage(Image.FromStream(stream), new PointF(e.Bounds.X, e.Bounds.Y)); } // Draw text if necessary if (showLabels) { // Same as for OnPaint event var txt = Config.localesFull[(int)Methods.General.getLocaleFromString(text)]; var limits = e.Graphics.MeasureString(txt, e.Font); var top = (24 - limits.Height) / 2; e.Graphics.DrawString(txt, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + 24, e.Bounds.Top + top); } // We need to do this, no wonder why :/ if ((e.Index == SelectedIndex) && (DroppedDown == false)) { e.DrawFocusRectangle(); } } }
/// <summary> /// Draw device ID types. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ServerIDTypeCB_DrawItem(object sender, DrawItemEventArgs e) { // If the index is invalid then simply exit. if (e.Index == -1 || e.Index >= AddressTypeCB.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. GXServerAddress target = (GXServerAddress)AddressTypeCB.Items[e.Index]; if (target == null) { return; } string name = target.HDLCAddress.ToString(); SizeF s = e.Graphics.MeasureString(name, f); e.Graphics.DrawString(name, f, b, e.Bounds); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.ListBox.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 (DesignMode) { base.OnDrawItem(e); return; } // Get the selected emitter to draw var emitter = (e.Index < 0 || e.Index >= Items.Count ? null : Items[e.Index]) as IParticleEmitter; // Let the base implementation handle an invalid item if (emitter == null) { base.OnDrawItem(e); return; } // Draw the item e.DrawBackground(); var txt = string.Format(_displayTextFormat, emitter.GetType().Name, emitter.Name); using (var brush = new SolidBrush(e.ForeColor)) { e.Graphics.DrawString(txt, e.Font, brush, e.Bounds); } e.DrawFocusRectangle(); }
/// <summary> /// drawns the icon and the name of the element in the dropdown list /// </summary> /// <param name="sender">the sender</param> /// <param name="e">the params</param> private void QuickSearchComboBox_DrawItem(object sender, DrawItemEventArgs e) { //get the selected element and its associated image if (0 <= e.Index && e.Index < this.Items.Count) { UML.UMLItem selectedElement = this.Items[e.Index] as UML.UMLItem; if (selectedElement != null) { Image elementImage = this.navigatorVisuals.getImage(selectedElement); //draw standard background and focusrectangle e.DrawBackground(); e.DrawFocusRectangle(); //draw the name of the element e.Graphics.DrawString(this.navigatorVisuals.getNodeName(selectedElement), e.Font, new SolidBrush(e.ForeColor), new Point(elementImage.Width + 2,e.Bounds.Y)); // draw the icon e.Graphics.DrawImage(elementImage, new Point(e.Bounds.X, e.Bounds.Y)); // draw tooltip if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { this.itemTooltip.Show(selectedElement.fqn, this, e.Bounds.Right, e.Bounds.Bottom); } else { this.itemTooltip.Hide(this); } } } }
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); }
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 ); }
protected override void OnDrawItem(DrawItemEventArgs e) { // Make sure we're not trying to draw something that isn't there. if (e.Index >= this.Items.Count || e.Index <= -1) return; // Get the item object. object item = this.Items[e.Index]; if (item == null) return; e.DrawBackground(); e.DrawFocusRectangle(); // Draw the item string text = item.ToString(); RectangleF textPos = e.Bounds; if (ItemImage != null) { e.Graphics.DrawImage(ItemImage, e.Bounds.X + ItemImagePadding.X, (e.Bounds.Bottom + e.Bounds.Top) / 2 - ItemImage.PhysicalDimension.Height / 2); textPos.X += ItemImage.PhysicalDimension.Width + ItemImagePadding.X * 2; } if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.White), textPos); } else { e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.Black), textPos); } }
private void cmb_Connection_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index < 0) return; ComboBox combo = sender as ComboBox; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight), e.Bounds); else e.Graphics.FillRectangle(new SolidBrush(combo.BackColor), e.Bounds); string text = combo.Items[e.Index].ToString(); if (!MainV2.MONO) { text = text + " "+ SerialPort.GetNiceName(text); } e.Graphics.DrawString(text, e.Font, new SolidBrush(combo.ForeColor), new Point(e.Bounds.X, e.Bounds.Y)); e.DrawFocusRectangle(); }
protected override void OnDrawItem(DrawItemEventArgs ea) { ea.DrawBackground(); ea.DrawFocusRectangle(); ComboxBoxExItem item; Size imageSize = _imageList.ImageSize; Rectangle bounds = ea.Bounds; try { item = (ComboxBoxExItem)Items[ea.Index]; if (item.ImageIndex != -1) { _imageList.Draw(ea.Graphics,bounds.X,bounds.Y,bounds.Width,bounds.Height , item.ImageIndex); // ea.Graphics.DrawString(item.Text, ea.Font, new SolidBrush(ea.ForeColor), bounds.Left+imageSize.Width, bounds.Top); } else { // ea.Graphics.DrawString(item.Text, ea.Font, new SolidBrush(ea.ForeColor), bounds.Left, bounds.Top); } } catch { if (ea.Index != -1) { // ea.Graphics.DrawString(Items[ea.Index].ToString(), ea.Font, new SolidBrush(ea.ForeColor), bounds.Left, bounds.Top); } else { // ea.Graphics.DrawString(Text, ea.Font, new SolidBrush(ea.ForeColor), bounds.Left, bounds.Top); } } base.OnDrawItem(ea); }
private void DrawItemHandler(object sender, DrawItemEventArgs e) { RectangleF rc = new RectangleF((float)(e.Bounds.X), (float)(e.Bounds.Y), (float)(e.Bounds.Width), (float)(e.Bounds.Height)); e.Graphics.FillRectangle(new SolidBrush(SystemColors.Control), rc); MenuItem s = (MenuItem)sender; string s1 = s.Text; StringFormat sf = new StringFormat(); RectangleF rcText = rc; rcText.Y += 2; rcText.X += 24; rcText.Width -= 20; if (e.State == (DrawItemState.NoAccelerator | DrawItemState.Selected)) { e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight), rc); e.Graphics.DrawString(s1, CurrentFont, new SolidBrush(SystemColors.HighlightText), rcText, sf); e.DrawFocusRectangle(); } else { e.Graphics.DrawString(s1, CurrentFont, new SolidBrush(SystemColors.ControlText), rcText, sf); } if (Ico != null) { e.Graphics.DrawImage(Ico, System.Convert.ToInt32(e.Bounds.X + 5), System.Convert.ToInt32((e.Bounds.Bottom + e.Bounds.Top) / 2 - Ico.Size.Height / 2)); } }
private void ColorChannel_ComboBox_DrawItem( object sender, DrawItemEventArgs e ) { e.DrawBackground(); Brush bg_brush; switch( e.Index ) { case 0: bg_brush = Brushes.Red; break; case 1: bg_brush = Brushes.LightGreen; break; case 2: bg_brush = Brushes.Blue; break; default: return; } e.Graphics.FillRectangle( bg_brush, e.Bounds.Left + 2, e.Bounds.Top + 2, e.Bounds.Width - 4, e.Bounds.Height - 4); if( (e.State & DrawItemState.Focus) != 0 ) e.DrawFocusRectangle(); }
private void PcListBox_DrawItem_1(object sender, DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); if (e.Index >= 0) { var ListBox = (ListBox)sender; var item = ListBox.Items[e.Index] as PCItem; var Color = item.ItemColor; if (item == ListBox.SelectedItem) { //Color = SystemColors.HighlightText; } e.Graphics.DrawString( item.ToString(), ListBox.Font, new SolidBrush(Color), e.Bounds ); } }
/// <summary> /// OnDrawItem override to draw our custom item. /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { // Validation check to prevent designer errors.. if (this.Items.Count <= 0) return; // Cast the incoming argument as a string.. var filePath = (string)this.Items[e.Index]; // Adjust the background based on selection.. e.Graphics.FillRectangle((e.State & DrawItemState.Selected) == DrawItemState.Selected ? Brushes.SkyBlue : Brushes.White, e.Bounds); // Draw seperator line.. e.Graphics.DrawLine(Pens.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y); // Draw the hair icon.. var bmp = new Bitmap(string.Format("{0}\\Data\\Hair\\{1}", Application.StartupPath, filePath)); e.Graphics.DrawImage(bmp, e.Bounds.X + this.Margin.Left, e.Bounds.Y + this.Margin.Top, 48, 48); // Calculate name string bounds.. var nameBounds = new Rectangle(e.Bounds.X + this.Margin.Horizontal + 48, e.Bounds.Y + this.Margin.Top + (e.Bounds.Height / 2) - (int)this.Font.GetHeight(), e.Bounds.Width - this.Margin.Right - 48 - this.Margin.Horizontal, (int)this.Font.GetHeight() + 2); var styleId = filePath.Replace("hair_", "").Replace(".png", ""); // Draw style information string.. e.Graphics.DrawString(string.Format("Hair Style: {0}", styleId), this.Font, Brushes.Black, nameBounds); // Draw the focused item rect.. e.DrawFocusRectangle(); }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index == -1) { base.OnDrawItem(e); return; } object item = Items[e.Index]; if (!(item is SkillDBSkill)) { base.OnDrawItem(e); return; } SkillDBSkill skill = (item as SkillDBSkill); e.DrawBackground(); e.DrawFocusRectangle(); if (skill.ImageExists == true) { e.Graphics.DrawImageUnscaled(skill.Image, new Point(e.Bounds.X, e.Bounds.Y)); } string text = skill.Name.Replace("_", " "); float stringPadddingY = (e.Graphics.MeasureString(text, Font).Height / 2); float stringPadddingX = 26; e.Graphics.DrawString(text, Font, new SolidBrush(ForeColor), new PointF(e.Bounds.X + stringPadddingX, e.Bounds.Y + stringPadddingY)); }
private void this_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) return; e.DrawBackground(); if ((e.State & DrawItemState.Selected) != 0) { e.Graphics.FillRectangle(_highlightbrush, e.Bounds); } EXItem item = (EXItem) this.Items[e.Index]; Rectangle bounds = e.Bounds; int x = bounds.X + 2; if (item.GetType() == typeof(EXImageItem)) { EXImageItem imgitem = (EXImageItem) item; if (imgitem.MyImage != null) { Image img = imgitem.MyImage; int y = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (img.Height / 2)) + 1; e.Graphics.DrawImage(img, x, y, img.Width, img.Height); x += img.Width + 2; } } else if (item.GetType() == typeof(EXMultipleImagesItem)) { EXMultipleImagesItem imgitem = (EXMultipleImagesItem) item; if (imgitem.MyImages != null) { for (int i = 0; i < imgitem.MyImages.Count; i++) { Image img = (Image) imgitem.MyImages[i]; int y = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (img.Height / 2)) + 1; e.Graphics.DrawImage(img, x, y, img.Width, img.Height); x += img.Width + 2; } } } int fonty = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (e.Font.Height / 2)); e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), x, fonty); e.DrawFocusRectangle(); }
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(); } }
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 ); } }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index < 0) { base.OnDrawItem(e); } else { object listItem = this.Items[e.Index]; ListControlConvertEventArgs args = new ListControlConvertEventArgs(listItem.ToString(), typeof(string), listItem); this.OnFormat(args); string str = (string) args.Value; if (!string.IsNullOrEmpty(str)) { e.DrawBackground(); TextRenderer.DrawText(e.Graphics, str, e.Font, e.Bounds, e.ForeColor, TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter); e.DrawFocusRectangle(); } else { int num = e.Bounds.Top + (e.Bounds.Height / 2); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Left, num, e.Bounds.Right, num); } } }
/// <summary> /// OnDrawItem override to draw our custom item. /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { // Validation check to prevent designer errors.. if (this.Items.Count <= 0) return; // Cast the incoming argument as a buff entry.. var buff = (Buff)this.Items[e.Index]; // Adjust the background based on selection.. e.Graphics.FillRectangle((e.State & DrawItemState.Selected) == DrawItemState.Selected ? Brushes.SkyBlue : Brushes.White, e.Bounds); // Draw seperator line.. e.Graphics.DrawLine(Pens.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y); // Draw the buff icon.. var bmp = new Bitmap(buff.Icon.LocalPath); e.Graphics.DrawImage(bmp, e.Bounds.X + this.Margin.Left, e.Bounds.Y + this.Margin.Top, 32, 32); // Calculate name string bounds.. var nameBounds = new Rectangle(e.Bounds.X + this.Margin.Horizontal + 32, e.Bounds.Y + this.Margin.Top, e.Bounds.Width - this.Margin.Right - 32 - this.Margin.Horizontal, (int)this.Font.GetHeight() + 2); // Draw buff information strings.. e.Graphics.DrawString(buff.Name, this.Font, Brushes.Black, nameBounds); // Draw the focused item rect.. e.DrawFocusRectangle(); }
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); }
//------------------------------------------------------------- private void DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); ClockDrawer drawer = new ClockDrawer(e.Graphics, e.Bounds); drawer.DrawFace(); e.DrawFocusRectangle(); }
private void DrawGradientItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); if (e.Index >= 0 && e.Index < Gradients.List.Count) { IGradient g = Gradients.List[e.Index]; GradientPainter.FillRectangle(e.Graphics, g, e.Bounds, GradientPainter.Direction.Right); } e.DrawFocusRectangle(); }
private void OnDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { try { Graphics grfx = e.Graphics; Color brushColor = ((ColorComboBoxItem)this.Items[e.Index]).Color; SolidBrush brush = new SolidBrush(brushColor); Rectangle rect; //Pen pen= new Pen(blackBrush); e.DrawBackground(); e.DrawFocusRectangle(); rect = e.Bounds; rect.X += 5; rect.Y += 2; rect.Width = 50; rect.Height = 10; //grfx.FillRectangle( whiteBrush, e.Bounds ); // fill entire back ground grfx.FillRectangle(brush, rect); grfx.DrawRectangle(Pens.Black, rect); rect.Offset(60, 0); rect.Height = 15; rect.Width = 150; grfx.DrawString(((ColorComboBoxItem)this.Items[e.Index]).Name, e.Font, _blackBrush, rect); /* * if (_hideText == false) * { * if (brushColor == Color.Black || brushColor == Color.MidnightBlue || brushColor == Color.DarkBlue || brushColor == Color.Indigo || brushColor == Color.MediumBlue || brushColor == Color.Maroon || brushColor == Color.Navy || brushColor == Color.Purple) ||{ || //grfx.DrawString( ( string )this.Items[ e.Index ], e.Font, whiteBrush, e.Bounds ); ||} ||else ||{ || //grfx.DrawString( ( string )this.Items[ e.Index ], e.Font, blackBrush, e.Bounds ); ||} || ||this.SelectionStart = 0; ||this.SelectionLength = 0; ||} ||else ||{ ||//grfx.DrawString( ( string )this.Items[ e.Index ], e.Font, new SolidBrush( GetColorFromString( ( string )this.Items[ e.Index ] ) ), e.Bounds ); ||}*/ } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void drawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); var br = lstBruches.Find(l => l.lbInd.Equals(sender) && l.ind == e.Index); if (br != null) { e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, br.br, e.Bounds, StringFormat.GenericDefault); } e.DrawFocusRectangle(); }
protected void event_color_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { ListBox uiControl = (ListBox)sender; if (e.Index < 0) //Don't We Have A List ¿ { e.DrawBackground(); e.DrawFocusRectangle(); return; } //Get Colour Object From Items List Color CurrColour = (Color)uiControl.Items[e.Index]; //Create A Rectangle To Fit New Item Rectangle ColourSize = new Rectangle(0, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); Brush ColourBrush; //New Colour Brush To Draw With e.DrawBackground(); //Draw Item's Background e.DrawFocusRectangle(); //Draw Item's Focus Rectangle if (e.State == System.Windows.Forms.DrawItemState.Selected) //If Item Selected { ColourBrush = Brushes.White; //Change To White } else { ColourBrush = Brushes.Black; //Change Back to Black } e.Graphics.DrawRectangle(new Pen(CurrColour), ColourSize); //Draw New Item Rectangle With Current Colour e.Graphics.FillRectangle(new SolidBrush(CurrColour), ColourSize); //Fill New Item rectangle With Current Colour //Add Border Around Rectangle //ColourSize.Inflate(1, 1); //Border Size //e.Graphics.DrawRectangle(Pens.Black, ColourSize); //Draw New Border //Draw Current Colour Name, In The Middle //e.Graphics.DrawString(CurrColour.Name, uiControl.Font, ColourBrush, e.Bounds.Height + 5, ((e.Bounds.Height - uiControl.Font.Height) / 2) + e.Bounds.Top); e.Graphics.DrawString(CurrColour.Name, uiControl.Font, ColourBrush, 0, ((e.Bounds.Height - uiControl.Font.Height) / 2) + e.Bounds.Top); }
public void DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { try { e.DrawBackground(); e.Graphics.DrawString(lstbox.Items[e.Index].ToString(), e.Font, new SolidBrush(lstbox.ForeColor), e.Bounds, StringFormat.GenericDefault); e.DrawFocusRectangle(); } catch { } }
private void dayList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { string text = ""; if (e.Index != -1) { text = ((DateTime)((ComboBox)sender).Items[e.Index]).ToString("MMM dd, yyyy"); } e.DrawBackground(); e.Graphics.DrawString(text, ((ComboBox)sender).Font, Brushes.Black, e.Bounds); e.DrawFocusRectangle(); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { base.OnDrawItem(e); if (DesignMode && Items.Count == 0) { return; } if (e.Index != ListBox.NoMatches) { object item = this.Items[e.Index]; if (disabledIndices.Contains(e.Index)) { e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); // SystemBrushes.InactiveBorder if (item != null) { e.Graphics.DrawString(item.ToString(), e.Font, SystemBrushes.GrayText, e.Bounds); } } else { if (SelectionMode == System.Windows.Forms.SelectionMode.None) { e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); if (item != null) { e.Graphics.DrawString(item.ToString(), e.Font, SystemBrushes.WindowText, e.Bounds); } } else { if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds); e.DrawFocusRectangle(); if (item != null) { e.Graphics.DrawString(item.ToString(), e.Font, SystemBrushes.HighlightText, e.Bounds); } } else { e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); if (item != null) { e.Graphics.DrawString(item.ToString(), e.Font, SystemBrushes.WindowText, e.Bounds); } } } } } }
private void ListBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { //INSTANT C# TODO TASK: The 'On Error Resume Next' statement is not converted by Instant C#: On Error Resume Next e.DrawBackground(); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(Brushes.ForestGreen, e.Bounds); } e.Graphics.DrawString(ListBox1.GetItemText(ListBox1.Items[e.Index]), e.Font, new SolidBrush(e.ForeColor), e.Bounds); e.DrawFocusRectangle(); }
private void comboDocs_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index < 0 || e.Index >= comboDocs.Items.Count) { return; } ComboItem ci = (ComboItem)comboDocs.Items[e.Index]; string strName = ci.ToString() + (ci.m_tmpd.IsModified() ? "*" : ""); e.DrawBackground(); e.Graphics.DrawString(strName, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y); e.DrawFocusRectangle(); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if (! Enabled) { this.BackColor = System.Drawing.SystemColors.Control; } else { this.BackColor = SystemColors.Window; } e.DrawBackground(); e.DrawFocusRectangle(); if (e.Index != -1) { string itemText = null; if (DisplayMember != null && DisplayMember.Length != 0) { itemText = FilterItemOnProperty(Items[e.Index], DisplayMember).ToString(); } else { itemText = this.Items[e.Index].ToString(); } Size imageSize = new Size(); int imgIdx = 0; if (mImageList != null && ! (mImageList.Images.Count == 0)) { imageSize = mImageList.ImageSize; imgIdx = getImageIndex(e.Index); } if (ImageIndexes != null && ! (ImageIndexes.Count == 0) && imgIdx != -1) { this.ImageList.Draw(e.Graphics, e.Bounds.Left + mImagePadding, e.Bounds.Top, imgIdx); e.Graphics.DrawString(itemText, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + mImagePadding + imageSize.Width + mImagePadding, e.Bounds.Top + mImagePadding); } else { e.Graphics.DrawString(itemText, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top); } } else { e.Graphics.DrawString(Text, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top); } base.OnDrawItem(e); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); Rectangle bounds = e.Bounds; // no item if (e.Index < 0 || e.Index >= Items.Count) { e.Graphics.DrawString(Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } else { int LabelOffset = 0; int ImageIndex = -1; string ItemText = Items[e.Index].ToString(); Color ItemColor = Color.FromKnownColor(KnownColor.Transparent); bool ItemMark = false; if (ImageList != null) { LabelOffset = ImageList.ImageSize.Width; } ImageListBoxItem Item = Items[e.Index] as ImageListBoxItem; if (Item != null) { ImageIndex = Item.ImageIndex; ItemColor = Item.ForeColor; ItemMark = Item.Mark; } // draw image, if available if (ImageList != null && ImageIndex >= 0 && ImageIndex < ImageList.Images.Count) { ImageList.Draw(e.Graphics, bounds.Left, bounds.Top, ImageIndex); } // draw label Color forecolor = (ItemColor != Color.FromKnownColor(KnownColor.Transparent)) ? ItemColor : e.ForeColor; Font font = ItemMark ? new Font(e.Font, FontStyle.Bold) : e.Font; e.Graphics.DrawString(ItemText, font, new SolidBrush(forecolor), bounds.Left + LabelOffset, bounds.Top); } base.OnDrawItem(e); }
private void ComboBoxDrawItems(object sender, System.Windows.Forms.DrawItemEventArgs e) { try { ComboBox comboBox = (ComboBox)sender; e.DrawBackground(); if (this.textAreaControl == null) { return; } if (e.Index == 0) { ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index]; if (CodeEditorControl.AutoListImages.Images.ContainsKey(item.imagekey) == false) { return; } e.Graphics.DrawImageUnscaled(CodeEditorControl.AutoListImages.Images[item.imagekey], new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height - CodeEditorControl.AutoListImages.ImageSize.Height) / 2)); Rectangle drawingRect = new Rectangle(e.Bounds.X + CodeEditorControl.AutoListImages.ImageSize.Width, e.Bounds.Y, e.Bounds.Width - CodeEditorControl.AutoListImages.ImageSize.Width, e.Bounds.Height); Brush drawItemBrush = SystemBrushes.WindowText; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { drawItemBrush = SystemBrushes.HighlightText; } if (!item.IsInCurrentPart) { drawItemBrush = SystemBrushes.ControlDark; } else if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveViewControl.Caret.Position.Y)) { drawItemBrush = SystemBrushes.ControlDark; } e.Graphics.DrawString(item.ToString(), s_font, drawItemBrush, drawingRect, s_drawStringFormat); } e.DrawFocusRectangle(); } catch (Exception ee) { } }
private void lineStyles_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); if ((e.State & DrawItemState.Focus) != 0) { e.DrawFocusRectangle(); } if (e.Index >= 0 && e.Index < lineStyles.Items.Count) { var col = new BindingList <IStroke>(); col.Add((IStroke)lineStyles.Items[e.Index]); FeaturePreviewRender.RenderPreviewLine(e.Graphics, new Rectangle(e.Bounds.Left + 1, e.Bounds.Top + 1, e.Bounds.Width - 2, e.Bounds.Height - 2), col); } }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { // The following method should generally be called before drawing. // It is actually superfluous here, since the subsequent drawing // will completely cover the area of interest. e.DrawBackground(); //The system provides the context //into which the owner custom-draws the required graphics. //The context into which to draw is e.graphics. //The index of the item to be painted is e.Index. //The painting should be done into the area described by e.Bounds. if (e.Index > 0) { Graphics g = e.Graphics; Rectangle r = e.Bounds; Rectangle rd = r; rd.Width = rd.Left + 25; Rectangle rt = r; r.X = rd.Right; string displayText = this.Items[e.Index].ToString(); HatchStyle hs = (HatchStyle)Enum.Parse(typeof(HatchStyle), displayText, true); // TODO add user selected foreground and background colors here HatchBrush b = new HatchBrush(hs, Color.Black, e.BackColor); g.DrawRectangle(new Pen(Color.Black, 2), rd.X + 3, rd.Y + 2, rd.Width - 4, rd.Height - 4); g.FillRectangle(b, new Rectangle(rd.X + 3, rd.Y + 2, rd.Width - 4, rd.Height - 4)); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; //If the current item has focus. if ((e.State & DrawItemState.Focus) == 0) { e.Graphics.FillRectangle(new SolidBrush(SystemColors.Window), r); e.Graphics.DrawString(displayText, this.Font, new SolidBrush(SystemColors.WindowText), r, sf); } else { e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight), r); e.Graphics.DrawString(displayText, this.Font, new SolidBrush(SystemColors.HighlightText), r, sf); } } //Draws a focus rectangle on the specified graphics surface and within the specified bounds. e.DrawFocusRectangle(); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { base.OnDrawItem(e); e.DrawBackground(); e.DrawFocusRectangle(); if (e.Index < 0) { return; } if (!(this.Items[e.Index] is ImageComboItem)) { e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top); return; } ImageComboItem CurrItem = this.Items[e.Index] as ImageComboItem; SizeF fontSize = e.Graphics.MeasureString(CurrItem.Text, CurrItem.Font); SolidBrush brush = new SolidBrush(CurrItem.ForeColor); int imageX = e.Bounds.Left; if (CurrItem.Text != string.Empty && CurrItem.TextAlign == EImageComboItemTextAlign.Left) { e.Graphics.DrawString(CurrItem.Text, CurrItem.Font, brush, e.Bounds.Left, e.Bounds.Top + (mImageList.ImageSize.Height / 2) - fontSize.Height / 2); } if (mImageList != null && CurrItem.ImageIndex != -1) { if (CurrItem.TextAlign == EImageComboItemTextAlign.Left) { imageX += (int)fontSize.Width + 7; } if (mImagePlace > imageX) { imageX = mImagePlace; } ImageList.Draw(e.Graphics, imageX, e.Bounds.Top, CurrItem.ImageIndex); } if (CurrItem.Text != string.Empty && CurrItem.TextAlign == EImageComboItemTextAlign.Right) { imageX += ImageList.ImageSize.Width + 7; e.Graphics.DrawString(CurrItem.Text, CurrItem.Font, brush, imageX, e.Bounds.Top + (mImageList.ImageSize.Height / 2) - fontSize.Height / 2); } }
// You must handle the DrawItem event for owner-drawn combo boxes. // This event handler changes the color, size and font of an // item based on its position in the array. private void ComboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { float size = 0; System.Drawing.Font myFont; FontFamily family = null; System.Drawing.Color animalColor = new System.Drawing.Color(); switch (e.Index) { case 0: size = 30; animalColor = System.Drawing.Color.Gray; family = FontFamily.GenericSansSerif; break; case 1: size = 10; animalColor = System.Drawing.Color.LawnGreen; family = FontFamily.GenericMonospace; break; case 2: size = 15; animalColor = System.Drawing.Color.Tan; family = FontFamily.GenericSansSerif; break; } // Draw the background of the item. e.DrawBackground(); // Create a square filled with the animals color. Vary the size // of the rectangle based on the length of the animals name. Rectangle rectangle = new Rectangle(2, e.Bounds.Top + 2, e.Bounds.Height, e.Bounds.Height - 4); e.Graphics.FillRectangle(new SolidBrush(animalColor), rectangle); // Draw each string in the array, using a different size, color, // and font for each item. myFont = new Font(family, size, FontStyle.Bold); e.Graphics.DrawString(animals[e.Index], myFont, System.Drawing.Brushes.Black, new RectangleF(e.Bounds.X + rectangle.Width, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); // Draw the focus rectangle if the mouse hovers over an item. e.DrawFocusRectangle(); }
// Changes the Playlist item 0 to be bold showing that it is the one currently playing private void Playlist_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); if (e.Index >= 0) { if (e.Index == CurrentlyPlaying) { e.Graphics.DrawString(Playlist.Items[e.Index].ToString(), new Font("Microsoft Sans Serif", 8, FontStyle.Bold), Brushes.Black, e.Bounds); } else { e.Graphics.DrawString(Playlist.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds); } } e.DrawFocusRectangle(); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); //ListBox lb1 = new ListBox(); lb1.DrawMode = DrawMode. CustomListBoxItem item; Rectangle bounds = e.Bounds; Size imageSize = new Size(0, 0); Image ImageAvatar; try { item = (CustomListBoxItem)Items[e.Index]; if (item.strAvatar != "") { // Draw Image ImageAvatar = ImageFromStr(item.strAvatar); e.Graphics.DrawImage(ImageAvatar, bounds.Left, bounds.Top, bounds.Height, bounds.Height); } // Draw Name e.Graphics.DrawString(item.Name, new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))) , new SolidBrush(e.ForeColor), bounds.Left + bounds.Height, bounds.Top); // Draw Username e.Graphics.DrawString(item.Username, new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0))) , new SolidBrush(e.ForeColor), bounds.Left + bounds.Height, bounds.Top + 17); // Draw UserGroupName e.Graphics.DrawString(item.UserGroupName, new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0))) , new SolidBrush(e.ForeColor), bounds.Left + bounds.Height, bounds.Bottom - 20); } catch { } base.OnDrawItem(e); }
private void DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); pen.Color = colorLabel.BackColor; Graphics g = e.Graphics; string style = (string)lineStyle.Items[e.Index]; for (DashStyle s = DashStyle.Solid; s < DashStyle.Custom; s++) { if (style == s.ToString()) { pen.DashStyle = s; } } g.DrawLine(pen, e.Bounds.X, e.Bounds.Y + e.Bounds.Height / 2, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height / 2); e.DrawFocusRectangle(); }
/// <summary> /// Standard DrawItem EventHandler for ListBox lbHatchStyles. /// </summary> /// <param name="sender">Standard sender object.</param> /// <param name="e">Standard DrawItemEventArgs object.</param> private void lbHatchStyles_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { SolidBrush brshText = new SolidBrush(e.ForeColor); string str = lbHatchStyles.Items[e.Index].ToString(); SizeF szfString = e.Graphics.MeasureString(str, e.Font); int iYPos = e.Bounds.Top + (e.Bounds.Height - (int)szfString.Height) / 2; int iXPos = iItemPadX + iHatchStyleBoxWidth + iItemPadX; e.DrawBackground(); e.Graphics.DrawString(str, e.Font, brshText, iXPos, iYPos); PaintHatchStyle(e, (HatchStyle)lbHatchStyles.Items[e.Index]); if (lbHatchStyles.SelectedIndex == e.Index) { e.DrawFocusRectangle(); } }
protected override void OnDrawItem(swf.DrawItemEventArgs e) { if (e.State.HasFlag(swf.DrawItemState.ComboBoxEdit)) { var bounds = e.Bounds; bounds.Inflate(2, 2); // only show the background color for the drop down, not for each item e.Graphics.FillRectangle(new sd.SolidBrush(BackColor), bounds); } else { e.DrawBackground(); } if (e.Index >= 0) { var item = Items[e.Index]; var bounds = e.Bounds; var etoitem = item as EtoComboBoxItem; var image = etoitem?.Image; if (image != null) { e.Graphics.DrawImage(image.ToSD(new Size(16, 16)), bounds.X, bounds.Y, 16, 16); bounds.X += 18; bounds.Width -= 18; } string text = item?.ToString(); var font = Font; if (FormatItem != null) { var args = new DropDownFormatEventArgs(etoitem.Value, e.Index, font.ToEto()); FormatItem.Invoke(this, args); font = args.Font.ToSD(); } // Determine the forecolor based on whether or not the item is selected swf.TextRenderer.DrawText(e.Graphics, text, font, bounds, ForeColor, swf.TextFormatFlags.Left); } e.DrawFocusRectangle(); }
/// <summary> /// 重繪 Combo Box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { ComboBox comBox = (ComboBox)sender; Graphics g = e.Graphics; Rectangle rec = e.Bounds; Font font = comBox.Font; if (e.Index > -1) { if (comBox.Items[e.Index] != null && (ComBox.ComboBoxItem)comBox.Items[e.Index] != null) { ComBox.ComboBoxItem comBoxItem = (ComBox.ComboBoxItem)comBox.Items[e.Index]; SolidBrush solidBrush = new SolidBrush(Color.LightSkyBlue); if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect)) { solidBrush = new SolidBrush(Color.LightSkyBlue); e.Graphics.FillRectangle(solidBrush, rec); } else { e.Graphics.FillRectangle(solidBrush, rec); } solidBrush.Dispose(); System.Drawing.StringFormat sf = new System.Drawing.StringFormat(); SolidBrush sb = new SolidBrush(comBoxItem.ForeColor); sf.Alignment = StringAlignment.Near; e.Graphics.DrawString(comBoxItem.Text, font, sb, rec, sf); e.DrawFocusRectangle(); sf = null; sb = null; } } }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if (DesignMode) { return; } e.DrawBackground(); e.DrawFocusRectangle(); GListBoxItem item; Rectangle bounds = e.Bounds; //Size imageSize = _myImageList.ImageSize; try { item = (GListBoxItem)Items[e.Index]; if (item.ImageIndex != -1) { //_myImageList.Draw(e.Graphics, bounds.Left,bounds.Top,item.ImageIndex); e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left //+imageSize.Width , bounds.Top); } else { e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } } catch { if (e.Index != -1) { e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } else { e.Graphics.DrawString(Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } } base.OnDrawItem(e); }
private void editTabs_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { Brush brush; Font f = new Font("Verdana", 8.25f, FontStyle.Bold); if (e.Index == this.editTabs.SelectedIndex) { e.Graphics.FillRectangle(Brushes.MintCream, e.Bounds); brush = Brushes.Green; } else { brush = Brushes.Gray; } e.Graphics.DrawString("X", f, Brushes.Red, e.Bounds.Right - 20, e.Bounds.Top + 6); e.Graphics.DrawString(this.editTabs.TabPages[e.Index].Text, f, brush, e.Bounds.Left + 12, e.Bounds.Top + 6); e.DrawFocusRectangle(); this.editTabs.SelectedTab.BackColor = Color.DarkTurquoise; }
/// <summary> /// /// </summary> static private void CLDrawListItem(Object sender, System.Windows.Forms.DrawItemEventArgs e) { ICompletionListItem item = completionList.Items[e.Index] as ICompletionListItem; e.DrawBackground(); Color fore = PluginBase.MainForm.GetThemeColor("CompletionList.ForeColor", SystemColors.WindowText); Color sel = PluginBase.MainForm.GetThemeColor("CompletionList.SelectedTextColor", SystemColors.HighlightText); bool selected = (e.State & DrawItemState.Selected) > 0; Brush textBrush = (selected) ? new SolidBrush(sel) : new SolidBrush(fore); Brush packageBrush = new SolidBrush(PluginBase.MainForm.GetThemeColor("CompletionList.PackageColor", Color.Gray)); Rectangle tbounds = new Rectangle(ScaleHelper.Scale(18), e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); if (item != null) { Graphics g = e.Graphics; float newHeight = e.Bounds.Height - 2; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(item.Icon, 1, e.Bounds.Top + ((e.Bounds.Height - newHeight) / 2), newHeight, newHeight); int p = item.Label.LastIndexOf('.'); if (p > 0 && !selected) { string package = item.Label.Substring(0, p + 1); g.DrawString(package, e.Font, packageBrush, tbounds, StringFormat.GenericDefault); int left = tbounds.Left + DrawHelper.MeasureDisplayStringWidth(e.Graphics, package, e.Font) - 2; if (left < tbounds.Right) { g.DrawString(item.Label.Substring(p + 1), e.Font, textBrush, left, tbounds.Top, StringFormat.GenericDefault); } } else { g.DrawString(item.Label, e.Font, textBrush, tbounds, StringFormat.GenericDefault); } } e.DrawFocusRectangle(); if ((item != null) && ((e.State & DrawItemState.Selected) > 0)) { UITools.Tip.Hide(); currentItem = item; tempoTip.Stop(); tempoTip.Start(); } }
public void ReplaceItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); try { if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(37, 37, 37)), e.Bounds); //37 37 37 } using (SolidBrush b = new SolidBrush(Color.FromArgb(66, 130, 181))) { e.Graphics.DrawString(base.GetItemText(base.Items[e.Index]), e.Font, b, e.Bounds); } } catch { } e.DrawFocusRectangle(); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); GListBoxItem item; Rectangle bounds = e.Bounds; Size imageSize = _myImageList.ImageSize; try { item = (GListBoxItem)Items[e.Index]; if (item.ImageIndex != -1) { _myImageList.Draw(e.Graphics, bounds.Left, bounds.Top, item.ImageIndex); e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left + imageSize.Width, bounds.Top); } else { e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } } catch { //design time it throws error, this try/catch was placed for that try { if (e.Index != -1) { e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } else { e.Graphics.DrawString(Text, e.Font, new SolidBrush(e.ForeColor), bounds.Left, bounds.Top); } } catch { } } base.OnDrawItem(e); }
/// <summary> /// Lorsque la listbox des nouvelles est dessine, on empeche que l'image scintille /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { ListBox listBox = sender as ListBox; if (listBox.Items.Count > 0) { // // Draw the background of the ListBox control for each item. // Create a new Brush and initialize to a Black colored brush // by default. // //On cast notre text string text = listBoxNouvelles.Items[e.Index].ToString(); e.DrawBackground(); Brush myBrush = Brushes.Black; // // Determine the color of the brush to draw each item based on // the index of the item to draw. // if (text.Contains("écrasé")) { myBrush = Brushes.Red; } // // Draw the current item text based on the current // Font and the custom brush settings. // e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault); // // If the ListBox has focus, draw a focus rectangle // around the selected item. // e.DrawFocusRectangle(); } }
private void ColorCB_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index == -1) { return; } ComboBox cmbColor = (ComboBox)sender; string itemString = cmbColor.Items[e.Index].ToString(); e.DrawBackground(); e.Graphics.DrawString("■", e.Font, new SolidBrush(Color.FromName(itemString)), new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); e.Graphics.DrawString(" " + itemString, e.Font, new SolidBrush(e.ForeColor), new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); e.DrawFocusRectangle(); }