/// <summary>Override for the drawing of the control to include a Close Tab button</summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { RectangleF tabTextArea = RectangleF.Empty; for(int nIndex = 0 ; nIndex < this.TabCount ; nIndex++) { tabTextArea = (RectangleF)this.GetTabRect(nIndex); using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].BackColor)) { //Clear the tab e.Graphics.FillRectangle(brush, tabTextArea); } Bitmap bmp = nIndex == this.SelectedIndex ? Resources.activeClose : Resources.inactiveClose; e.Graphics.DrawImage(bmp, tabTextArea.X + tabTextArea.Width - (CLOSE_ICON_PADDING + CLOSE_ICON_SIZE), tabTextArea.Y + CLOSE_ICON_PADDING, CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); bmp.Dispose(); string str = this.TabPages[nIndex].Text; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].ForeColor)) { //Draw the tab header text e.Graphics.DrawString(str, this.Font, brush, tabTextArea,stringFormat); } } }
/// <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 || !ControlHelper.DrawListItem<KeyValuePair<GameMessage, string>>(Items, e, x => new KeyValuePair<string, string>(x.Key.ToString(), x.Value))) base.OnDrawItem(e); }
protected override void OnDrawItem(DrawItemEventArgs e) { // base.OnDrawItem(e); Graphics g = e.Graphics; Rectangle rectBounds = e.Bounds; Rectangle rectFill = new Rectangle(rectBounds.Left + 2, rectBounds.Top + 2, rectBounds.Width - 4, rectBounds.Height - 4); bool bFocused = (((e.State & DrawItemState.Focus) != DrawItemState.None) || ((e.State & DrawItemState.Selected) != DrawItemState.None)); // e.DrawBackground(); // e.DrawFocusRectangle(); using(SolidBrush sbBack = new SolidBrush(bFocused ? SystemColors.Highlight : SystemColors.Menu)) { g.FillRectangle(sbBack, rectBounds); } using(SolidBrush sb = new SolidBrush(m_clr)) { g.FillRectangle(sb, rectFill); } }
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 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); }
/// <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); }
protected override void OnDrawItem(DrawItemEventArgs e) { Graphics grfx = e.Graphics; Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height); rectColor.Inflate(-1, -1); Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height, e.Bounds.Top, e.Bounds.Width - 2 * e.Bounds.Height, e.Bounds.Height); if (this.Enabled) e.DrawBackground(); LinearGradientShape item = e.Index >= 0 ? (LinearGradientShape)Items[e.Index] : LinearGradientShape.Linear; Rectangle rectShape = new Rectangle(rectColor.X + rectColor.Width / 4, rectColor.Y, rectColor.Width / 2, rectColor.Height); using (LinearGradientBrush br = new LinearGradientBrush(rectShape, e.ForeColor, e.BackColor, LinearGradientMode.Horizontal)) { if (item == LinearGradientShape.Triangular) br.SetBlendTriangularShape(0.5f); else if (item == LinearGradientShape.SigmaBell) br.SetSigmaBellShape(0.5f); grfx.FillRectangle(br, rectColor); } SolidBrush foreColorBrush = new SolidBrush(e.ForeColor); grfx.DrawString(item.ToString(), Font, foreColorBrush, rectText); }
protected override void OnDrawItem(DrawItemEventArgs e) { Graphics g = e.Graphics; Color BlockColor = Color.Empty; int left = RECTCOLOR_LEFT; if (e.State == DrawItemState.Selected || e.State == DrawItemState.None) e.DrawBackground(); if (e.Index == -1) { BlockColor = SelectedIndex < 0 ? BackColor : DesignerUtility.ColorFromHtml(this.Text, Color.Empty); } else BlockColor = DesignerUtility.ColorFromHtml((string)this.Items[e.Index], Color.Empty); // Fill rectangle if (BlockColor.IsEmpty && this.Text.StartsWith("=")) { g.DrawString("fx", this.Font, Brushes.Black, e.Bounds); } else { g.FillRectangle(new SolidBrush(BlockColor), left, e.Bounds.Top + RECTCOLOR_TOP, RECTCOLOR_WIDTH, ItemHeight - 2 * RECTCOLOR_TOP); } base.OnDrawItem(e); }
// 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(); } }
protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); if (e.Index != -1) { if ((e.State & DrawItemState.Selected) != DrawItemState.None) { LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, this.MouseColor, this.mouseGradientColor, LinearGradientMode.Vertical); Rectangle rect = new Rectangle(1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2); e.Graphics.FillRectangle(brush, rect); Pen pen = new Pen(this.ItemBorderColor); e.Graphics.DrawRectangle(pen, rect); } else { SolidBrush brush2 = new SolidBrush(this.DropBackColor); e.Graphics.FillRectangle(brush2, e.Bounds); } string s = base.Items[e.Index].ToString(); Color color = ((e.State & DrawItemState.Selected) != DrawItemState.None) ? this.ItemHoverForeColor : this.ForeColor; StringFormat format = new StringFormat { LineAlignment = StringAlignment.Center }; e.Graphics.DrawString(s, this.Font, new SolidBrush(color), e.Bounds, format); } }
protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); //Draw play button e.Graphics.DrawImage(PlayButtonImage, e.Bounds.GetPlayButtonRectangleFromItemRectangle()); }
private void settings4_4_language_DrawItem(object sender, DrawItemEventArgs e) { Font objFonts = new Font(this.Font.Name, 14, FontStyle.Bold); e.DrawBackground(); e.Graphics.DrawString(settings4_4_language.Items[e.Index].ToString(), objFonts, new SolidBrush(e.ForeColor), new Point(e.Bounds.Left, e.Bounds.Top)); }
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); } }
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(); }
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); }
private void WeSayListBox_DrawItem(object sender, DrawItemEventArgs e) { //surprisingly, this *is* called with bogus values, by the system if (e.Index < 0 || e.Index >= Items.Count) { return; } if (Items[e.Index] == _itemToNotDrawYet) { return; } // Draw the background of the ListBox control for each item. e.DrawBackground(); // Define the default color of the brush as black. Brush myBrush = Brushes.Black; // Draw the current item text based on the current Font and the custom brush settings. e.Graphics.DrawString(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(); }
public void Drawitem(object sender, DrawItemEventArgs e) { if (e.Index < 0) return; e.DrawBackground(); e.DrawFocusRectangle(); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; //-- if selected if (e.State.ToString().IndexOf("Selected,") >= 0) { //-- Base e.Graphics.FillRectangle(new SolidBrush(_SelectedColor), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); //-- Text e.Graphics.DrawString(" " + ListBx.Items[e.Index].ToString(), new Font("Segoe UI", 8), Brushes.White, e.Bounds.X, e.Bounds.Y + 2); } else { //-- Base e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(51, 53, 55)), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); //-- Text e.Graphics.DrawString(" " + ListBx.Items[e.Index].ToString(), new Font("Segoe UI", 8), Brushes.White, e.Bounds.X, e.Bounds.Y + 2); } e.Graphics.Dispose(); }
/// <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(); }
public virtual void DrawPanel(DrawItemEventArgs e) { string text = base.Text; if ((text != null) && (text.Length != 0)) { int num = 0; StringFormat format = new StringFormat(StringFormatFlags.NoWrap); format.LineAlignment = StringAlignment.Center; format.HotkeyPrefix = HotkeyPrefix.Hide; format.Trimming = StringTrimming.EllipsisCharacter; switch (base.Alignment) { case HorizontalAlignment.Right: format.Alignment = StringAlignment.Far; break; case HorizontalAlignment.Center: format.Alignment = StringAlignment.Center; break; default: format.Alignment = StringAlignment.Near; num = 3; break; } Rectangle layoutRectangle = new Rectangle((e.Bounds.X + 1) + num, e.Bounds.Y, (e.Bounds.Width - 2) - num, e.Bounds.Height); e.Graphics.DrawString(base.Text, base.Parent.Font, SystemBrushes.ControlText, layoutRectangle, format); format.Dispose(); } this.DrawPanelBorder(e); }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index < 0 || e.Index >= Items.Count) return; var item = (Item)this.Items[e.Index]; var image = item.Title; var drawWidth = (int)(image.Width * scalingFactor); var drawHeight = (int)(image.Height * scalingFactor); var destRect = new Rectangle(e.Bounds.Location, new Size(drawWidth, drawHeight)); // we need to manually add xMargin to the offset again, as it's // already subtracted from the actual list width in GetListWidth destRect.Offset((GetListWidth() - drawWidth + xMargin) / 2, yMargin); // background e.Graphics.FillRectangle(Brushes.Black, e.Bounds); // separator if (e.Index > 0) { e.Graphics.DrawLine(Pens.DimGray, e.Bounds.Left + 5, e.Bounds.Top + 1, e.Bounds.Right - 5, e.Bounds.Top + 1); destRect.Offset(0, 3); } // title e.Graphics.DrawImage(image, destRect, new Rectangle(new Point(), image.Size), GraphicsUnit.Pixel); }
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; }
/// <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> /// Creates a new instance of the <see>CustomItemDrawData</see> object. /// </summary> /// <param name="args">The <see>DrawItemEventArgs</see> on which this instance is based.</param> /// <param name="itemToDraw">The object to render.</param> public CustomItemDrawData(DrawItemEventArgs args, object itemToDraw) : base(args.Graphics, args.Font, args.Bounds, args.Index, args.State, args.ForeColor, args.BackColor) { Debug.Assert(!object.ReferenceEquals(null, itemToDraw)); m_item = itemToDraw; }
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 ) { 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 ); } } }
private void comboBox2_DrawItem(object sender, DrawItemEventArgs e) { Rectangle listBound = e.Bounds; Font listFond = null; switch (e.Index) { case 0: listFond = new Font(e.Font, FontStyle.Regular); break; case 2: listFond = new Font(e.Font, FontStyle.Bold); break; case 1: listFond = new Font(e.Font, FontStyle.Italic); break; case 3: listFond = new Font(e.Font, FontStyle.Bold|FontStyle.Italic); break; } string str = comboBox2.Items[e.Index].ToString(); Brush bru = new SolidBrush(Color.Black); Graphics g = e.Graphics; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { g.FillRectangle(new SolidBrush(Color.FromArgb(0xFF,0x33,0x99,0xFF)), listBound); g.DrawString(str, listFond, new SolidBrush(Color.White), listBound); } else { g.FillRectangle(new SolidBrush(Color.White), listBound); g.DrawString(str, listFond, bru, listBound); } }
private void cbxServerLocation_DrawItem(object sender, DrawItemEventArgs e) { string strImageFont = "Arial"; System.Drawing.FontStyle fsFontStyle = FontStyle.Regular; if (!IsFontInstalled(strImageFont)) strImageFont = this.Font.FontFamily.ToString(); Font objFont = new Font(strImageFont, 11, fsFontStyle, System.Drawing.GraphicsUnit.Pixel); // Let's highlight the currently selected item like any well // behaved combo box should try { e.Graphics.FillRectangle(Brushes.Bisque, e.Bounds); e.Graphics.DrawString(m_fszFileServerZone[e.Index].FileServerName, objFont, Brushes.Black, new Point(m_fszFileServerZone[e.Index].FileServerFlag.Width * 2, e.Bounds.Y)); e.Graphics.DrawImage(m_fszFileServerZone[e.Index].FileServerFlag, new Point(e.Bounds.X, e.Bounds.Y)); if ((e.State & DrawItemState.Focus) == 0) { e.Graphics.FillRectangle(Brushes.White, e.Bounds); e.Graphics.DrawString(m_fszFileServerZone[e.Index].FileServerName, objFont, Brushes.Black, new Point(m_fszFileServerZone[e.Index].FileServerFlag.Width * 2, e.Bounds.Y)); e.Graphics.DrawImage(m_fszFileServerZone[e.Index].FileServerFlag, new Point(e.Bounds.X, e.Bounds.Y)); } } catch { } }
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); }
//http://stackoverflow.com/a/9144861 /// <summary>Overrides the OnDrawItem for the CheckedListBox so that we can customize how the items are drawn.</summary> /// <param name="e">The System.Windows.Forms.DrawItemEventArgs object with the details</param> /// <remarks>A CheckedListBox can only have one item selected at a time and it's always the item in focus. /// So, don't draw an item as selected since the selection colors are hideous.</remarks> protected override void OnDrawItem(DrawItemEventArgs e) { Color foreColor = this.ForeColor; Color backColor = this.BackColor; DrawItemState s2 = e.State; //If the item is in focus, then it should always have the focus rect. //Sometimes it comes in with Focus and NoFocusRect. //This is annoying and the user can't tell where their focus is, so give it the rect. /*if ((s2 & DrawItemState.Focus) == DrawItemState.Focus) { s2 &= ~DrawItemState.NoFocusRect; }*/ //Turn off the selected state. Note that the color has to be overridden as well, but I just did that for all drawing since I want them to match. if ((s2 & DrawItemState.Selected) == DrawItemState.Selected) { s2 &= ~DrawItemState.Selected; } //Compile the new drawing args and let the base draw the item. DrawItemEventArgs e2 = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, s2, foreColor, backColor); base.OnDrawItem(e2); }
/// <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.Extended.UMLItem selectedElement = this.Items[e.Index] as UML.Extended.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); } } } }
/// <summary> /// 绘制菜单项的快键键的方法 /// </summary> private static void DrawShortCutText(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi) { if (mi.Shortcut != Shortcut.None && mi.ShowShortcut == true) { SizeF scSize = e.Graphics.MeasureString(mi.Shortcut.ToString(), Globals.menuFont); Rectangle rect = new Rectangle(e.Bounds.Width - Convert.ToInt32(scSize.Width) - Globals.PIC_AREA_SIZE, e.Bounds.Y, Convert.ToInt32(scSize.Width) + 5, e.Bounds.Height); StringFormat sf = new StringFormat(); sf.FormatFlags = StringFormatFlags.DirectionRightToLeft; sf.LineAlignment = StringAlignment.Center; if (mi.Enabled) { e.Graphics.DrawString(mi.Shortcut.ToString(), Globals.menuFont, new SolidBrush(Globals.TextColor), rect, sf); } else { e.Graphics.DrawString(mi.Shortcut.ToString(), Globals.menuFont, new SolidBrush(Globals.TextDisabledColor), rect, sf); } } }
private void tabControl_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { bool selected = e.Index == tabControl.SelectedIndex; Font font = selected ? new Font(e.Font, FontStyle.Bold) : e.Font; Brush backBrush = new SolidBrush(selected ? SystemColors.Control : SystemColors.Window); Brush foreBrush = new SolidBrush(SystemColors.ControlText); e.Graphics.FillRectangle(backBrush, e.Bounds); Rectangle r = e.Bounds; r.Y += 3; r.Height -= 3; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; e.Graphics.DrawString(tabControl.TabPages[e.Index].Text, font, foreBrush, r, sf); foreBrush.Dispose(); backBrush.Dispose(); if (selected) { font.Dispose(); } }
private void TabPagesDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { //Change appearance of tabcontrol //Brush backBrush; //Brush foreBrush; if (e.Index == tabControl1.SelectedIndex) { backBrush = new SolidBrush(Color.SteelBlue); // backBrush = new SolidBrush(Color.SkyBlue); // backBrush = new SolidBrush(Color.DeepSkyBlue); // backBrush = new SolidBrush(Color.DodgerBlue); foreBrush = new SolidBrush(Color.White); } else { backBrush = new SolidBrush(Color.Snow); foreBrush = new SolidBrush(Color.DimGray); } e.Graphics.FillRectangle(backBrush, e.Bounds); //You may need to write the label here also? StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; Rectangle r = e.Bounds; r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3); e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, foreBrush, r, sf); //NEw code //tabControl1.ColorScheme.TabBackground = Color.Transparent; //tabControl1.ColorScheme.TabBackground2 = Color.Transparent; //TabControl.BackColor = Color.Transparent; }
private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { Brush brush; // Create the brush using the ForeColor specified by the DrawItemEventArgs if (foreColorBrush == null) { foreColorBrush = new SolidBrush(e.ForeColor); } else if (foreColorBrush.Color != e.ForeColor) { // The control's ForeColor has changed, so dispose of the cached brush and // create a new one. foreColorBrush.Dispose(); foreColorBrush = new SolidBrush(e.ForeColor); } // Select the appropriate brush depending on if the item is selected. // Since State can be a combinateion (bit-flag) of enum values, you can't use // "==" to compare them. if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { brush = SystemBrushes.HighlightText; } else { brush = foreColorBrush; } // Perform the painting. Font font = ((ListBoxFontItem)listBox1.Items[e.Index]).Font; e.DrawBackground(); e.Graphics.DrawString(font.Name, font, brush, e.Bounds); e.DrawFocusRectangle(); }
private void tabControl1_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e) { Graphics g = e.Graphics; Brush textBrush; TabPage tabPage = tabControl1.TabPages[e.Index]; Rectangle tabBounds = tabControl1.GetTabRect(e.Index); if (e.State == DrawItemState.Selected) { textBrush = new SolidBrush(Color.Black); g.FillRectangle(Brushes.Gray, e.Bounds); } else { textBrush = new System.Drawing.SolidBrush(e.ForeColor); e.DrawBackground(); } Font tabFont = new Font("Arial", (float)15.0, FontStyle.Bold, GraphicsUnit.Pixel); StringFormat stringFlags = new StringFormat(); stringFlags.Alignment = StringAlignment.Center; stringFlags.LineAlignment = StringAlignment.Center; g.DrawString(tabPage.Text, tabFont, textBrush, tabBounds, new StringFormat(stringFlags)); }
public void ReplaceItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { e.DrawBackground(); Rectangle Rect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); try { if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(new SolidBrush(_SqaureColour), Rect); e.Graphics.DrawString(base.GetItemText(base.Items[e.Index]), Font, new SolidBrush(_FontColour), 1, e.Bounds.Top + 2); } else { e.Graphics.FillRectangle(new SolidBrush(_BaseColour), Rect); e.Graphics.DrawString(base.GetItemText(base.Items[e.Index]), Font, new SolidBrush(_FontColour), 1, e.Bounds.Top + 2); } } catch { } e.DrawFocusRectangle(); Invalidate(); }
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) { string text = Items[e.Index].ToString(); // Determine the forecolor based on whether or not the item is selected swf.TextRenderer.DrawText(e.Graphics, text, Font, e.Bounds, ForeColor, swf.TextFormatFlags.Left); } e.DrawFocusRectangle(); }
private void AllOrders_DrawItem(System.Object sender, System.Windows.Forms.DrawItemEventArgs e) { // ----- Draw a single display item. System.Drawing.Brush useBrush; OrderInfo itemDetail; // ----- 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(); // ----- Extract the detail from the list. itemDetail = (OrderInfo)AllOrders.Items[e.Index]; // ----- Draw the text of the item. e.Graphics.DrawString(itemDetail.ID.ToString(), e.Font, useBrush, 0, e.Bounds.Top); e.Graphics.DrawString(string.Format("{0:M/d/yyyy}", itemDetail.OrderDate), e.Font, useBrush, ColOrderDate.Left - ColOrderID.Left, e.Bounds.Top); e.Graphics.DrawString(string.Format("{0:c}", itemDetail.OrderTotal), e.Font, useBrush, ColOrderTotal.Left - ColOrderID.Left, e.Bounds.Top); // ----- If the ListBox has focus, draw a focus rectangle. e.DrawFocusRectangle(); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if (e.Index < 0) { return; } IComboboxItem item = this.Items[e.Index] as IComboboxItem; if (null != item) { //if (e.Index == 5) //{ // e.DrawBackground(); // int startX = e.Bounds.Left + 5; // int startY = (e.Bounds.Y); // Point p1 = new Point(startX, startY); // int endX = e.Bounds.Right - 5; // int endY = (e.Bounds.Y); // ComboBoxItem cbitem = (ComboBoxItem)this.Items[e.Index]; // Point p2 = new Point(endX, endY); // base.OnDrawItem(e); // Pen SolidmyPen = new Pen(item.foreColor, 1); // Pen DashedPen = new Pen(item.foreColor, 1); // DashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; // Pen DashDot = new Pen(item.foreColor, 1); // DashDot.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; // // Pen DashedPen = new Pen(item.foreColor, (Int32)this.Items[e.Index]); // Bitmap myBitmap = new Bitmap(cbitem.); // Graphics graphicsObj; // graphicsObj = Graphics.FromImage(myBitmap); //} //else item.DrawItem(e); } }
private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { ComboBox cmb = (ComboBox)sender; if (e.Index == -1) { return; } if (sender == null) { return; } SolidBrush selectedBrush = (SolidBrush)cmb.Items[e.Index]; Graphics g = e.Graphics; // 如果选择了项,则绘制正确的背景颜色和聚焦框 e.DrawBackground(); e.DrawFocusRectangle(); // 绘制颜色的预览框 Rectangle rectPreview = e.Bounds; rectPreview.Offset(3, 3); rectPreview.Width = 20; rectPreview.Height -= 4; g.DrawRectangle(new Pen(e.ForeColor), rectPreview); // 获取选定颜色的相应 Brush 对象,并填充预览框 rectPreview.Offset(1, 1); rectPreview.Width -= 2; rectPreview.Height -= 2; g.FillRectangle(selectedBrush, rectPreview); // 绘制选定颜色的名称 g.DrawString(selectedBrush.Color.ToString(), Font, new SolidBrush(e.ForeColor), e.Bounds.X + 30, e.Bounds.Y + 1); }
private void tabControl_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e) { Graphics g = e.Graphics; Brush _textBrush; // Get the item from the collection. TabPage _tabPage = tabControl.TabPages[e.Index]; // Get the real bounds for the tab rectangle. Rectangle _tabBounds = tabControl.GetTabRect(e.Index); if (e.State == DrawItemState.Selected) { // Draw a different background color, and don't paint a focus rectangle. _textBrush = new SolidBrush(Color.Black); //g.FillRectangle(Brushes.LightGray, e.Bounds); if (tabControl.TabPages[e.Index] == reportsTab) { g.FillRectangle(Brushes.DarkCyan, e.Bounds); } if (tabControl.TabPages[e.Index] == newMajorPlantTab) { g.FillRectangle(Brushes.DarkCyan, e.Bounds); } if (tabControl.TabPages[e.Index] == newSmallPlantTab) { g.FillRectangle(Brushes.DarkCyan, e.Bounds); } if (tabControl.TabPages[e.Index] == newOrderTab) { g.FillRectangle(Brushes.DarkCyan, e.Bounds); } if (tabControl.TabPages[e.Index] == jobCardsTab) { g.FillRectangle(Brushes.DarkCyan, e.Bounds); } if (tabControl.TabPages[e.Index] == oilTab) { g.FillRectangle(Brushes.DarkCyan, e.Bounds); } if (tabControl.TabPages[e.Index] == archiveTab) { g.FillRectangle(Brushes.DarkCyan, e.Bounds); } } else { _textBrush = new System.Drawing.SolidBrush(e.ForeColor); e.DrawBackground(); //g.FillRectangle(Brushes.AliceBlue, e.Bounds); if (tabControl.TabPages[e.Index] == reportsTab) { g.FillRectangle(Brushes.LightBlue, e.Bounds); } if (tabControl.TabPages[e.Index] == newMajorPlantTab) { g.FillRectangle(Brushes.LightBlue, e.Bounds); } if (tabControl.TabPages[e.Index] == newSmallPlantTab) { g.FillRectangle(Brushes.LightBlue, e.Bounds); } if (tabControl.TabPages[e.Index] == newOrderTab) { g.FillRectangle(Brushes.LightBlue, e.Bounds); } if (tabControl.TabPages[e.Index] == jobCardsTab) { g.FillRectangle(Brushes.LightBlue, e.Bounds); } if (tabControl.TabPages[e.Index] == oilTab) { g.FillRectangle(Brushes.LightBlue, e.Bounds); } if (tabControl.TabPages[e.Index] == archiveTab) { g.FillRectangle(Brushes.LightBlue, e.Bounds); } } // Use our own font. Font _tabFont = new Font("Arial", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel); // Draw string. Center the text. StringFormat _stringFlags = new StringFormat(); _stringFlags.Alignment = StringAlignment.Center; _stringFlags.LineAlignment = StringAlignment.Center; g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags)); }
void ComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { OnDrawItem(e); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if (this.Parent == this.GetMainMenu()) { Brush brush; brush = SystemBrushes.Control; e.Graphics.FillRectangle(brush, e.Bounds); if ( ((e.State & DrawItemState.Selected) == DrawItemState.Selected) || ((e.State & DrawItemState.HotLight) == DrawItemState.HotLight) ) { Rectangle highlightRect = e.Bounds; highlightRect.X += 1; highlightRect.Y += 1; highlightRect.Width -= 3; Pen pen = SystemPens.Highlight; if ((e.State & DrawItemState.HotLight) == DrawItemState.HotLight) { highlightRect.Height -= 2; brush = new SolidBrush(HighlightBrushColor()); e.Graphics.FillRectangle(brush, highlightRect); brush.Dispose(); e.Graphics.DrawRectangle(pen, highlightRect); } else { highlightRect.X -= 1; highlightRect.Height -= 1; brush = SystemBrushes.Control; e.Graphics.FillRectangle(brush, highlightRect); highlightRect.Height -= 1; highlightRect.Width -= 1; pen = SystemPens.ControlDark; e.Graphics.DrawLine(pen, highlightRect.X, highlightRect.Y + highlightRect.Height, highlightRect.X, highlightRect.Y); e.Graphics.DrawLine(pen, highlightRect.X, highlightRect.Y, highlightRect.X + highlightRect.Width, highlightRect.Y); e.Graphics.DrawLine(pen, highlightRect.X + highlightRect.Width, highlightRect.Y, highlightRect.X + highlightRect.Width, highlightRect.Y + highlightRect.Height); //pen = SystemPens.ControlDark; pen = new Pen(Color.FromArgb(128, Color.Black)); e.Graphics.DrawLine(pen, highlightRect.X + highlightRect.Width + 1, highlightRect.Y + 4, highlightRect.X + highlightRect.Width + 1, highlightRect.Y + highlightRect.Height); pen.Dispose(); //pen = SystemPens.ControlDarkDark; pen = new Pen(Color.FromArgb(64, Color.Black)); e.Graphics.DrawLine(pen, highlightRect.X + highlightRect.Width + 2, highlightRect.Y + 4, highlightRect.X + highlightRect.Width + 2, highlightRect.Y + highlightRect.Height); pen.Dispose(); pen = new Pen(Color.FromArgb(32, Color.Black)); e.Graphics.DrawLine(pen, highlightRect.X + highlightRect.Width + 3, highlightRect.Y + 5, highlightRect.X + highlightRect.Width + 3, highlightRect.Y + highlightRect.Height); pen.Dispose(); } } brush = SystemBrushes.WindowText; RectangleF layoutRect = new RectangleF(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height); layoutRect.X += 4; DrawCaption(e.Graphics, this.Text, brush, layoutRect, ((e.State & DrawItemState.NoAccelerator) != DrawItemState.NoAccelerator), false, this.Enabled); } else { Brush iconBarBrush = SystemBrushes.Control; e.Graphics.FillRectangle(iconBarBrush, e.Bounds.X, e.Bounds.Y, iconWidth, e.Bounds.Height); Rectangle rectOut = e.Bounds; if (this.Text.Equals("-")) { rectOut.X += iconWidth; Brush brush; if (System.Environment.OSVersion.Version.Major > 4) { brush = SystemBrushes.Menu; } else { brush = SystemBrushes.Window; } e.Graphics.FillRectangle(brush, rectOut); Pen pen = SystemPens.ControlDark; e.Graphics.DrawLine(pen, iconWidth + iconToTextSeparatorWidth, e.Bounds.Y + 1, e.Bounds.Width, e.Bounds.Y + 1); } else { Rectangle rectIn = rectOut; Brush brush; rectIn.Height -= 1; if ( ((e.State & DrawItemState.Selected) == DrawItemState.Selected) && (this.Enabled)) { if (System.Environment.OSVersion.Version.Major > 4) { brush = SystemBrushes.Menu; } else { brush = SystemBrushes.Window; } e.Graphics.FillRectangle(brush, rectIn); brush = new SolidBrush(Color.FromArgb(64, Color.FromKnownColor(KnownColor.Highlight))); e.Graphics.FillRectangle(brush, rectIn); brush.Dispose(); Pen pen = SystemPens.Highlight; Rectangle highlightRect = rectIn; highlightRect.Width -= 1; e.Graphics.DrawRectangle(pen, highlightRect); } else { rectOut.X += iconWidth; rectOut.Width -= iconWidth; if (System.Environment.OSVersion.Version.Major > 4) { brush = SystemBrushes.Menu; } else { brush = SystemBrushes.Window; } e.Graphics.FillRectangle(brush, rectOut); } DrawIcon( e.Graphics, e.Bounds, ((e.State & DrawItemState.Selected) == DrawItemState.Selected), this.Checked, this.RadioCheck, this.Enabled); brush = SystemBrushes.WindowText; RectangleF layoutRect = new RectangleF(e.Bounds.X + iconWidth + iconToTextSeparatorWidth, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); DrawCaption(e.Graphics, this.Text, brush, layoutRect, ((e.State & DrawItemState.NoAccelerator) != DrawItemState.NoAccelerator), false, this.Enabled); if (this.ShowShortcut) { if (this.Shortcut != Shortcut.None) { string shortCut = ShortcutToString(this.Shortcut); DrawCaption(e.Graphics, shortCut, brush, layoutRect, false, true, this.Enabled); } } } } }
private void Menu_DrawItem(System.Object sender, System.Windows.Forms.DrawItemEventArgs e) { MenuItem MiItem = ((MenuItem)(sender)); float MargenX = 12; float MargenY = 4; if (MiItem.Parent == Aplicacion.FormularioPrincipal.MainMenu) { MargenX = 6; MargenY = 2; } StringFormat FormatoTexto = new StringFormat(); FormatoTexto.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; SolidBrush Fondo = new SolidBrush(System.Drawing.SystemColors.Menu); e.Graphics.FillRectangle(Fondo, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); // e.Graphics.FillRectangle(New SolidBrush(PaletaCambiarBrillo(SystemColors.Menu, -40)), e.Bounds.X + 1, e.Bounds.Y, 20, e.Bounds.Height - 1) if (MiItem.Text == "-") { e.Graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.SystemColors.ControlDark), e.Bounds.X + 3, e.Bounds.Y + 1, e.Bounds.Width - 6, e.Bounds.Height - 3); } else if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { SolidBrush Resalte = new SolidBrush(System.Drawing.SystemColors.Highlight); Pen Recuadro = new Pen(System.Drawing.SystemColors.Highlight); SolidBrush Texto = new SolidBrush(System.Drawing.SystemColors.HighlightText); // e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.None e.Graphics.FillRectangle(Resalte, e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1); // e.Graphics.FillRectangle(New SolidBrush(PaletaCambiarBrillo(SystemColors.Highlight, 40)), e.Bounds.X + 1, e.Bounds.Y, 20, e.Bounds.Height - 1) e.Graphics.DrawRectangle(Recuadro, e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1); string texto = MiItem.Text; int lastDosPunto = MiItem.Text.LastIndexOf(':'); if (lastDosPunto == MiItem.Text.Length - 1) { int indImg = MiItem.Text.LastIndexOf(':', --lastDosPunto); string nomImg = MiItem.Text.Substring(indImg + 1, lastDosPunto - indImg); IconosMenu(e, nomImg); texto = " " + texto.Substring(0, indImg); } e.Graphics.DrawString(texto, Lazaro.Pres.DisplayStyles.Template.Current.MenuFont, Texto, e.Bounds.X + MargenX, e.Bounds.Y + MargenY, FormatoTexto); Recuadro.Dispose(); Resalte.Dispose(); Texto.Dispose(); } else if ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled) { SolidBrush Texto = new SolidBrush(System.Drawing.SystemColors.GrayText); // e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.None e.Graphics.DrawString(MiItem.Text, Lazaro.Pres.DisplayStyles.Template.Current.MenuFont, Texto, e.Bounds.X + MargenX, e.Bounds.Y + MargenY, FormatoTexto); Texto.Dispose(); } else { SolidBrush Texto = new SolidBrush(System.Drawing.SystemColors.MenuText); string texto = MiItem.Text; // e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.None int lastDosPunto = MiItem.Text.LastIndexOf(':'); if (lastDosPunto == MiItem.Text.Length - 1) { int indImg = MiItem.Text.LastIndexOf(':', --lastDosPunto); string nomImg = MiItem.Text.Substring(indImg + 1, lastDosPunto - indImg); IconosMenu(e, nomImg); texto = " " + texto.Substring(0, indImg); } e.Graphics.DrawString(texto, Lazaro.Pres.DisplayStyles.Template.Current.MenuFont, Texto, e.Bounds.X + MargenX, e.Bounds.Y + MargenY, FormatoTexto); Texto.Dispose(); } Fondo.Dispose(); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { MenuWithHandler definition = Tag as MenuWithHandler; if (this.Text == "-") { Rectangle LeftSquare = e.Bounds; Rectangle Text = e.Bounds; LeftSquare.Width = ButtonImages.ButtonImageList.ImageSize.Width + 6; Text.Offset(LeftSquare.Width, 0); Text.Width -= LeftSquare.Width; LinearGradientBrush leftBrush = new LinearGradientBrush(LeftSquare, SystemColors.ControlLightLight, SystemColors.ControlDark, LinearGradientMode.Horizontal); e.Graphics.FillRectangle(leftBrush, LeftSquare); e.Graphics.FillRectangle(SystemBrushes.ControlLightLight, Text); e.Graphics.DrawLine(SystemPens.Control, e.Bounds.Left + (ButtonImages.ButtonImageList.ImageSize.Width + 6) + ButtonImages.ButtonImageList.ImageSize.Width / 2, e.Bounds.Top + 1, e.Bounds.Right, e.Bounds.Top + 1); } else { if (this.Parent is MainMenu) { if ((e.State & DrawItemState.HotLight) != 0) { Color c = Color.FromArgb( ((int)SystemColors.ActiveCaption.R + 2 * (int)SystemColors.ControlLightLight.R) / 3, ((int)SystemColors.ActiveCaption.G + 2 * (int)SystemColors.ControlLightLight.G) / 3, ((int)SystemColors.ActiveCaption.B + 2 * (int)SystemColors.ControlLightLight.B) / 3); e.Graphics.FillRectangle(new SolidBrush(c), e.Bounds); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Left, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Top); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Right - 1, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Bottom - 1); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Right - 1, e.Bounds.Bottom - 1, e.Bounds.Left, e.Bounds.Bottom - 1); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Left, e.Bounds.Top); } else { e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds); } float TextX = e.Bounds.Left; float TextY = e.Bounds.Top + (e.Bounds.Height - SystemInformation.MenuFont.GetHeight(e.Graphics)) / 2; StringFormat sf = StringFormat.GenericDefault; sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; Brush textBrush; if (!Enabled) { textBrush = SystemBrushes.FromSystemColor(SystemColors.GrayText); } else { textBrush = SystemBrushes.WindowText; } e.Graphics.DrawString(this.Text, SystemInformation.MenuFont, textBrush, TextX, TextY, sf); } else { Rectangle LeftSquare = e.Bounds; Rectangle Text = e.Bounds; LeftSquare.Width = ButtonImages.ButtonImageList.ImageSize.Width + 6; Text.Offset(LeftSquare.Width, 0); Text.Width -= LeftSquare.Width; LinearGradientBrush leftBrush = new LinearGradientBrush(LeftSquare, SystemColors.ControlLightLight, SystemColors.ControlDark, LinearGradientMode.Horizontal); if ((e.State & DrawItemState.Selected) != 0) { Color c = Color.FromArgb( ((int)SystemColors.ActiveCaption.R + 2 * (int)SystemColors.ControlLightLight.R) / 3, ((int)SystemColors.ActiveCaption.G + 2 * (int)SystemColors.ControlLightLight.G) / 3, ((int)SystemColors.ActiveCaption.B + 2 * (int)SystemColors.ControlLightLight.B) / 3); e.Graphics.FillRectangle(new SolidBrush(c), e.Bounds); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Left, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Top); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Right - 1, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Bottom - 1); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Right - 1, e.Bounds.Bottom - 1, e.Bounds.Left, e.Bounds.Bottom - 1); e.Graphics.DrawLine(SystemPens.ControlText, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Left, e.Bounds.Top); } else { e.Graphics.FillRectangle(leftBrush, LeftSquare); e.Graphics.FillRectangle(SystemBrushes.ControlLightLight, Text); } float TextX = e.Bounds.Left + (ButtonImages.ButtonImageList.ImageSize.Width + 6) + ButtonImages.ButtonImageList.ImageSize.Width / 2; float TextY = e.Bounds.Top + (e.Bounds.Height - SystemInformation.MenuFont.GetHeight(e.Graphics)) / 2; StringFormat sf = StringFormat.GenericDefault; sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; Brush textBrush; if (!Enabled) { textBrush = SystemBrushes.FromSystemColor(SystemColors.GrayText); } else { textBrush = SystemBrushes.WindowText; } e.Graphics.DrawString(this.Text, SystemInformation.MenuFont, textBrush, TextX, TextY, sf); string shortcut = definition.Shortcut;// GetShortcutString(); if (!string.IsNullOrEmpty(shortcut)) { SizeF sz = e.Graphics.MeasureString(shortcut, SystemInformation.MenuFont); e.Graphics.DrawString(shortcut, SystemInformation.MenuFont, textBrush, e.Bounds.Right - e.Bounds.Height / 2 - sz.Width, TextY, sf); } int dx = (e.Bounds.Height - ButtonImages.ButtonImageList.ImageSize.Height) / 2; if (definition.ImageIndex >= 0) { int ind = definition.ImageIndex; if (ind >= 10000) { ind = ind - 10000 + ButtonImages.OffsetUserImages; } if (Enabled) { ButtonImages.ButtonImageList.Draw(e.Graphics, e.Bounds.Left + 3, e.Bounds.Top + 3, ind); } else { ControlPaint.DrawImageDisabled(e.Graphics, ButtonImages.ButtonImageList.Images[ind], e.Bounds.Left + 3, e.Bounds.Top + 3, Color.FromArgb(0, 0, 0, 0)); } } if ((e.State & DrawItemState.Checked) != 0 || doubleChecked) { if (definition.ImageIndex < 0) { ButtonImages.ButtonImageList.Draw(e.Graphics, e.Bounds.Left + 3, e.Bounds.Top + 3, 84); // the red check mark } int x1 = e.Bounds.Left + 1; int y1 = e.Bounds.Top + 1; int x2 = x1 + ButtonImages.ButtonImageList.ImageSize.Width + 4; int y2 = y1 + ButtonImages.ButtonImageList.ImageSize.Height + 4; e.Graphics.DrawLine(SystemPens.ControlText, x1, y1, x2, y1); e.Graphics.DrawLine(SystemPens.ControlText, x2, y1, x2, y2); e.Graphics.DrawLine(SystemPens.ControlText, x2, y2, x1, y2); e.Graphics.DrawLine(SystemPens.ControlText, x1, y2, x1, y1); } } } }
private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { ComboBox a = combo4; comboDrawDo(e, a); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { int LineBold = 4; if (backImage == null || drawAll) { drawAll = false; InitFrm(e.Bounds.Width, e.Bounds.Height); } using (Graphics g = Graphics.FromImage(backImage)) { g.Clear(this.BackColor); g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; Rectangle tmpRect; //画选中项背景色 if ((e.State & System.Windows.Forms.DrawItemState.Selected) == System.Windows.Forms.DrawItemState.Selected) { g.FillRectangle(new SolidBrush(TitleColor), new Rectangle(new Point(0, 0), e.Bounds.Size)); } else { g.FillPath(new SolidBrush(TitleColor), TitlePath); } //画前段颜色 Color TmpColor = Color.Red; if (e.Index >= 0 && itemColor.Length > 0) { TmpColor = itemColor[(e.Index % itemColor.Length)]; } g.FillPath(new SolidBrush(TmpColor), IconPath); if (tail) //画尾巴 { g.FillPath(new SolidBrush(TmpColor), TailPath); } switch (iconStyle)//画图标 { case IconStyleList.无: break; default: if (icon != null) { tmpRect = new Rectangle(LineBold, LineBold, e.Bounds.Height - LineBold * 2, e.Bounds.Height - LineBold * 2); g.DrawImage(icon, tmpRect, new Rectangle(0, 0, icon.Width, icon.Height), GraphicsUnit.Pixel); } else { tmpRect = new Rectangle(LineBold, LineBold, e.Bounds.Height - LineBold * 2, e.Bounds.Height - LineBold * 2); g.DrawImage(All.Properties.Resources.Identity_Card, tmpRect, new Rectangle(0, 0, All.Properties.Resources.News.Width, All.Properties.Resources.News.Height), GraphicsUnit.Pixel); } break; } //画上面颜色 StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; if (e.Index >= 0 && e.Index < this.Items.Count) { g.DrawString(this.Items[e.Index].ToString(), titleFont, new SolidBrush(ForeColor), new RectangleF(TitlePath.PathPoints[0], new SizeF(e.Bounds.Width - e.Bounds.Height / 2, e.Bounds.Height * 11f / 15)), sf); } if (e.Index < 0) { g.DrawString(this.title, titleFont, new SolidBrush(ForeColor), new RectangleF(TitlePath.PathPoints[0], new SizeF(e.Bounds.Width + e.Bounds.Height / 2, e.Bounds.Height * 11f / 15)), sf); } sf.Dispose(); } e.Graphics.DrawImageUnscaled(backImage, e.Bounds.Left, e.Bounds.Top); //base.OnDrawItem(e); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { base.OnDrawItem(e); //DrawItemState stateFocus = (/*DrawItemState.Focus | */DrawItemState.Selected); //DrawItemState stateSelected = DrawItemState.ComboBoxEdit; DrawItemState stateFocus = DrawItemState.Focus; DrawItemState stateSelected = DrawItemState.Selected; if ((e.State & stateSelected) == stateSelected) { e.Graphics.FillRectangle(new SolidBrush(BackgroundColorItemSelected), e.Bounds); } else if ((e.State & stateFocus) == stateFocus) { e.Graphics.FillRectangle(new SolidBrush(BackgroundColorItemFocused), e.Bounds); } else { e.Graphics.FillRectangle(new SolidBrush(Parent.BackColor), e.Bounds); } //e.DrawFocusRectangle(); if (e.Index < 0) { return; } if (!(this.Items[e.Index] is ImageComboBoxItem)) { //System.Diagnostics.Debug.WriteLine(this.Items[e.Index] + ": " + e.State); e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(ForeColor), e.Bounds.Left, e.Bounds.Top); return; } //System.Diagnostics.Debug.WriteLine((this.Items[e.Index] as ImageComboBoxItem).Text + ": " + e.State); ImageComboBoxItem CurrItem = this.Items[e.Index] as ImageComboBoxItem; 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 == EImageComboBoxTextAlign.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 == EImageComboBoxTextAlign.Left) { imageX += (int)fontSize.Width; } if (mImagePlace > imageX) { imageX = mImagePlace; } ImageList.Draw(e.Graphics, imageX, e.Bounds.Top, CurrItem.ImageIndex); } if (CurrItem.Text != string.Empty && CurrItem.TextAlign == EImageComboBoxTextAlign.Right) { imageX += ImageList.ImageSize.Width + 10; e.Graphics.DrawString(CurrItem.Text, CurrItem.Font, brush, imageX, e.Bounds.Top + (mImageList.ImageSize.Height / 2) - fontSize.Height / 2); } }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if (this.Visible) { base.OnDrawItem(e); // Show/Hide the accelerator StringFormat strfmt = new StringFormat(); if ((e.State & DrawItemState.NoAccelerator) == 0) { strfmt.HotkeyPrefix = HotkeyPrefix.Show; } else { strfmt.HotkeyPrefix = HotkeyPrefix.Hide; } //Calculate check mark and text rectangles Rectangle rectCheck = e.Bounds; rectCheck.Width = (int)Math.Ceiling(SystemInformation.MenuCheckSize.Width * (double)rectCheck.Height / SystemInformation.MenuCheckSize.Height); int buffer = (rectCheck.Width / 2); Rectangle rectText = e.Bounds; Rectangle rectImage = e.Bounds; rectImage.Width = (int)Math.Ceiling(m_image.Width * (double)rectImage.Height / m_image.Height); if (m_alignLeft) { rectImage.X += rectCheck.Width; rectText.X = rectImage.X + rectImage.Width + buffer; rectText.Width -= rectCheck.Width + rectImage.Width; } else { rectText.X += rectCheck.Width; rectText.Width -= rectCheck.Width + rectImage.Width + buffer; rectImage.X = rectText.X + rectText.Width; rectImage.Width = (int)Math.Ceiling(m_image.Width * (double)e.Bounds.Height / m_image.Height); } // // Time to draw... // //Selected item color for rendering image backgrounds Color foreColor, backColor; Brush foreBrush, backBrush; if ((e.State & DrawItemState.Selected) != 0) { foreColor = SystemColors.HighlightText; backColor = SystemColors.Highlight; } else { foreColor = SystemColors.MenuText; backColor = SystemColors.Menu; } foreBrush = SystemBrushes.FromSystemColor(foreColor); backBrush = SystemBrushes.FromSystemColor(backColor); //Fill background e.Graphics.FillRectangle(backBrush, e.Bounds); //Draw glyph if ((e.State & DrawItemState.Checked) != 0) { DrawMenuGlyph(e.Graphics, rectCheck, foreColor, backColor); } //Draw text e.Graphics.DrawString(this.Text, m_font, foreBrush, rectText, strfmt); //TODO: //Currently the back color being swapped is White, if one of the fore colors being displayed //was actually white then it would also get swapped to the background color. Need to //make the color to be swapped Color.Transparent. DrawImage(e.Graphics, m_image, rectImage, Color.Red, m_color, Color.White, backColor); } }
private void lbSystem_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { DrawItem(false, sender, e); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { Rectangle rec = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); DataGridViewMultiColumnComboColumn column = ownerCell.OwningColumn as DataGridViewMultiColumnComboColumn; DataTable valuesTbl = column.DataSource as DataTable; string joinByField = column.ValueMember; SolidBrush NormalText = new SolidBrush(System.Drawing.SystemColors.ControlText); //If there is an item if (e.Index > -1) { DataRowView currentRow = Items[e.Index] as DataRowView; if (currentRow != null) { DataRow row = currentRow.Row; string currentText = GetItemText(Items[e.Index]); //first redraw the normal while background SolidBrush normalBack = new SolidBrush(Color.White); //TODO: fix to be system edit box background e.Graphics.FillRectangle(normalBack, rec); if (DroppedDown && !(Margin.Top == rec.Top)) { int currentOffset = rec.Left; SolidBrush HightlightedBack = new SolidBrush(System.Drawing.SystemColors.Highlight); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { //draw selected color background e.Graphics.FillRectangle(HightlightedBack, rec); } bool addBorder = false; object valueItem; foreach (object dataRowItem in row.ItemArray) { valueItem = dataRowItem; string value = dataRowItem.ToString(); //TODO: support for different types!!! if (addBorder) { //draw dividing line //currentOffset ++; SolidBrush gridBrush = new SolidBrush(Color.Gray); //TODO: make the border color configurable long linesNum = lineWidth; while (linesNum > 0) { linesNum--; Point first = new Point(rec.Left + currentOffset, rec.Top); Point last = new Point(rec.Left + currentOffset, rec.Bottom); e.Graphics.DrawLine(new Pen(gridBrush), first, last); currentOffset++; } } else { addBorder = true; } SizeF extent = e.Graphics.MeasureString(value, e.Font); decimal width = (decimal)extent.Width; //measure the string that we are goin to draw and cut it with wrapping if too large Rectangle textRec = new Rectangle(currentOffset, rec.Y, (int)decimal.Ceiling(width), rec.Height); //now draw the relevant to this column value text if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { //draw selected SolidBrush HightlightedText = new SolidBrush(System.Drawing.SystemColors.HighlightText); //now redraw the backgrond it order to wrap the previous field if was too large e.Graphics.FillRectangle(HightlightedBack, currentOffset, rec.Y, fixedAlignColumnSize, extent.Height); //draw text as is e.Graphics.DrawString(value, e.Font, HightlightedText, textRec); } else { //now redraw the backgrond it order to wrap the previous field if was too large e.Graphics.FillRectangle(normalBack, currentOffset, rec.Y, fixedAlignColumnSize, extent.Height); //draw text as is e.Graphics.DrawString(value, e.Font, NormalText, textRec); } //advance the offset to the next position currentOffset += fixedAlignColumnSize; } } else { //if happens when the combo is closed, draw single standard item view e.Graphics.DrawString(currentText, e.Font, NormalText, rec); } } } }
private void lbWeb_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { DrawItem(true, sender, e); }
public DrawItemEventArgs(System.Windows.Forms.DrawItemEventArgs e, DisplayItem item) : base(e.Graphics, e.Font, e.Bounds, e.Index, e.State, e.ForeColor, e.BackColor) { DisplayItem = item; }
sealed protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { OnDrawItem(new DrawItemEventArgs(e, GetDisplayItem(e.Index))); }
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if (e.Index < 0) { return; } if (gp == null) { Rectangle r = e.Bounds; int angle = 180; r.Width--; r.Height--; //r.Inflate(-1, - radius/2); //r.Offset(0, (radius/2)); gp = new GraphicsPath(); // top left gp.AddArc(r.X, r.Y, radius, radius, angle, 90); angle += 90; // top right gp.AddArc(r.Right - radius, r.Y, radius, radius, angle, 90); angle += 90; // bottom right gp.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, angle, 90); angle += 90; // bottom left gp.AddArc(r.X, r.Bottom - radius, radius, radius, angle, 90); gp.CloseAllFigures(); } if (borderpen == null) { borderpen = new Pen(SystemColors.Highlight, 1); //borderpen.Alignment = PenAlignment.Center; } bool selected = (e.State & DrawItemState.Selected) != 0; //normal AA looks bad e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //e.Graphics.PixelOffsetMode = PixelOffsetMode.None; string word1 = Text; Rectangle r2 = e.Bounds; r2.Width = r2.Height + 2; r2.X--; r2.Height += 2; r2.Y--; Rectangle r4 = e.Bounds; r4.Inflate(1, 1); //r4.Offset(-1,-1); e.Graphics.FillRectangle(SystemBrushes.Window, r4); //e.DrawBackground(); if (!(Items[e.Index] is CodeModel.ICodeElement)) { if (gradb == null) { LinearGradientBrush gb = new LinearGradientBrush(r2, SystemColors.Control, SystemColors.ControlDark, 0f); gb.SetSigmaBellShape(0.9f, 0.2f); gradb = gb; } e.Graphics.FillRectangle(gradb, r2); } int h = SystemInformation.MenuHeight; Brush b = SystemBrushes.ControlText; if (selected) { Rectangle r = e.Bounds; //Console.WriteLine(r); r.Width -= 1; r.Height -= 1; Rectangle r3 = r; r3.Width -= SystemInformation.MenuHeight; r3.X += SystemInformation.MenuHeight + 1; if (selbg == null) { r2.X -= r.Height / 2; r2.Height *= 2; LinearGradientBrush gb = new LinearGradientBrush(r2, Color.FromArgb(120, SystemColors.ControlLightLight), Color.FromArgb(120, SystemColors.Highlight), 90f); gb.SetSigmaBellShape(0.6f, 0.9f); selbg = gb; } e.Graphics.FillPath(selbg, gp); e.Graphics.DrawPath(borderpen, gp); } { Rectangle r = e.Bounds; r.Width = r.Height; r.X++; r.X++; r.Y++; r.Y++; if (!selected) { //r.X++; //r.Y++; } IImageListProviderService ips = ServiceHost.ImageListProvider; if (ips != null) { int i = ips[Items[e.Index]]; if (i >= 0) { int f = (int)((e.Bounds.Height - 16) / 2f); if ((e.State & DrawItemState.Focus) != 0) { ips.ImageList.Draw(e.Graphics, f + 3, e.Bounds.Top + f + 1, i); } else { ips.ImageList.Draw(e.Graphics, f + 3, e.Bounds.Top + f + 1, i); } } } if (!selected) { //r.X--; //r.Y--; } float fh = (float)font.FontFamily.GetCellAscent(0) / font.FontFamily.GetEmHeight(0); float bh = (float)font.FontFamily.GetCellDescent(0) / font.FontFamily.GetEmHeight(0); int hh = ((int)(float)(e.Bounds.Height - (fh - bh / 2) * font.Height) / 2); Type t = Items[e.Index] as Type; if (t == null) { t = Items[e.Index].GetType(); } Build.Project p = Items[e.Index] as Build.Project; if (p != null) { e.Graphics.DrawString(p.ProjectName, SystemInformation.MenuFont, b, r.Right + 1, e.Bounds.Top + hh); } else { Languages.Language l = Items[e.Index] as Languages.Language; if (l != null) { e.Graphics.DrawString(l.Name, SystemInformation.MenuFont, b, r.Right + 1, e.Bounds.Top + hh); } else { CodeModel.ICodeElement cl = Items[e.Index] as CodeModel.ICodeElement; if (cl != null) { e.Graphics.DrawString(cl is CodeModel.ICodeType ? cl.Fullname : ((cl is CodeModel.ICodeMethod || cl is CodeModel.ICodeField || cl is CodeModel.ICodeProperty) ? cl.ToString() : cl.Name), SystemInformation.MenuFont, b, r.Right + 1, e.Bounds.Top + hh); } else { e.Graphics.DrawString(NameAttribute.GetName(t), SystemInformation.MenuFont, b, r.Right + 1, e.Bounds.Top + hh); } } } gp.Dispose(); gp = null; if (gradb != null) { gradb.Dispose(); gradb = null; } if (selbg != null) { selbg.Dispose(); selbg = null; } } }
/// <summary> /// This event occurs when a row in the DropDown pane is drawn. /// </summary> /// <param name="e">The DrawItemEventArgs for this event.</param> /// <returns>void</returns> protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { Rectangle[] BackGroundRectangleCol = new Rectangle[MAXCOLUMN]; Rectangle[] ImageRectangleCol = new Rectangle[MAXCOLUMN]; System.Int32[] ColumnStartX = new int[MAXCOLUMN]; System.Int32 ColumnStartY; System.Drawing.StringFormat pStringFormat; System.Int32 mItemIndex; // Set the different brushes SolidBrush DefaultBackGroundBrush = new System.Drawing.SolidBrush(this.BackColor); SolidBrush SelectedBackGroundBrush = new System.Drawing.SolidBrush(System.Drawing.SystemColors.Highlight); SolidBrush DefaultForeGroundBrush = new System.Drawing.SolidBrush(this.ForeColor); SolidBrush SelectedForeGroundBrush = new System.Drawing.SolidBrush(System.Drawing.SystemColors.HighlightText); // Preset the base rectangle Rectangle BackGroundRectangle = e.Bounds; ColumnStartY = BackGroundRectangle.Y; int CountingX = BackGroundRectangle.X; for (int counter = 0; counter < MAXCOLUMN; counter++) { // Preset boundaries ColumnStartX[counter] = CountingX; CountingX += FColumnWidth[counter]; // Preset the rectangles BackGroundRectangleCol[counter] = BackGroundRectangle; BackGroundRectangleCol[counter].X = ColumnStartX[counter]; ImageRectangleCol[counter] = BackGroundRectangleCol[counter]; ImageRectangleCol[counter].Width = ImageRectangleCol[counter].Height; } if (e.Index >= 0) { BackGroundRectangle.Width = BackGroundRectangle.Left + this.DropDownWidth; pStringFormat = new System.Drawing.StringFormat(); pStringFormat.Alignment = System.Drawing.StringAlignment.Near; // Get the "right" index mItemIndex = e.Index; String[] StringColumn = new string[MAXCOLUMN]; // Getting the items into a string; for (int counter = 0; counter < this.ColumnNum; counter++) { Int32 ColumnIndex = this.Get_ColumnNumber(this.FDisplayInColumn[counter]); if (ColumnIndex != -1) { StringColumn[counter] = this.Get_ItemString(mItemIndex, ColumnIndex); } } // Draw every single item. First the selected Items. if ((e.State & System.Windows.Forms.DrawItemState.Selected) == System.Windows.Forms.DrawItemState.Selected) { for (int counter = 0; counter < this.ColumnNum; counter++) { DrawDropDownEntry( this.FColumnWidth[counter], e, SelectedBackGroundBrush, SelectedForeGroundBrush, BackGroundRectangleCol[counter], ImageRectangleCol[counter], counter, StringColumn[counter], pStringFormat, ColumnStartX[counter], ColumnStartY); } } else { for (int counter = 0; counter < this.ColumnNum; counter++) { DrawDropDownEntry( this.FColumnWidth[counter], e, DefaultBackGroundBrush, DefaultForeGroundBrush, BackGroundRectangleCol[counter], ImageRectangleCol[counter], counter, StringColumn[counter], pStringFormat, ColumnStartX[counter], ColumnStartY); } } } DrawGridlines(BackGroundRectangle, e); }
private void comboDrawDo(System.Windows.Forms.DrawItemEventArgs e, ComboBox comboBox) { // http://www.dhirajranka.com/2012/01/set-combobox-item-color/ if (e.Index < 0) { e.DrawBackground(); e.DrawFocusRectangle(); return; } Rectangle SizeRect = new Rectangle(2, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); Brush ComboBrush = Brushes.Black; e.DrawBackground(); e.DrawFocusRectangle(); Color CurrentColor = Color.Red; if (e.Index == 0) { CurrentColor = Color.Black; ComboBrush = Brushes.White; } else if (e.Index == 1) { CurrentColor = Color.Brown; } else if (e.Index == 2) { CurrentColor = Color.Red; } else if (e.Index == 3) { CurrentColor = Color.Orange; } else if (e.Index == 4) { CurrentColor = Color.Yellow; } else if (e.Index == 5) { CurrentColor = Color.Green; } else if (e.Index == 6) { CurrentColor = Color.Blue; } else if (e.Index == 7) { CurrentColor = Color.Violet; } else if (e.Index == 8) { CurrentColor = Color.Gray; } else if (e.Index == 9) { CurrentColor = Color.White; } e.Graphics.DrawRectangle(new Pen(CurrentColor), SizeRect); e.Graphics.FillRectangle(new SolidBrush(CurrentColor), SizeRect); e.Graphics.DrawString(comboBox.Items[e.Index].ToString(), comboBox.Font, ComboBrush, e.Bounds.X, e.Bounds.Y); }
private void treeListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { /* 0 stands for SB_HORZ */ int leftEdge = GetScrollPos(treeListBox.Handle, 0); if (leftEdge != this.leftEdge) { this.leftEdge = leftEdge; RedoColumnLayout(); } int position = 0; Graphics g = e.Graphics; ListBox treeView = treeListBox; if (e.Index < 0 || e.Index >= treeView.Items.Count) { return; } StringFormat sf = new StringFormat(StringFormatFlags.NoWrap); sf.Trimming = StringTrimming.EllipsisCharacter; TreeNodeBase node = (TreeNodeBase)Items[e.Index]; int crossover = (treeListBox.ItemHeight - 1) * (1 + node.depth); g.FillRectangle(new SolidBrush(Color.White), position, e.Bounds.Top, crossover, e.Bounds.Height); Rectangle itemRect = new Rectangle(crossover, e.Bounds.Top, e.Bounds.Right - crossover, e.Bounds.Height); g.FillRectangle(new SolidBrush(e.BackColor), itemRect); if (e.State == DrawItemState.Focus) { ControlPaint.DrawFocusRectangle(g, itemRect, e.ForeColor, e.BackColor); } Pen grayPen = new Pen(Color.LightGray); g.DrawLine(grayPen, 0, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1); Font fontToUse = treeOwner.GetFont(TokenObject, node); Color color = treeOwner.GetColor(TokenObject, node, (e.State & DrawItemState.Selected) != DrawItemState.Selected); Brush brush = new SolidBrush(color); Region oldClip = g.Clip; foreach (DiffColumn c in columns) { ColumnInformation current = c.ColumnInformation; Rectangle rect = new Rectangle(position, e.Bounds.Top, c.Width, e.Bounds.Height); g.Clip = new Region(rect); string res = treeOwner.GetInfo(TokenObject, node, current).ToString(); if (current.ColumnType == ColumnInformation.ColumnTypes.Tree) { rect.Offset((1 + node.depth) * (treeListBox.ItemHeight - 1), 0); rect.Width -= (1 + node.depth) * (treeListBox.ItemHeight - 1); if (node.HasKids) { Pen p = new Pen(Color.Gray); int y0 = e.Bounds.Top; int x0 = position + node.depth * (treeListBox.ItemHeight - 1); g.DrawRectangle(p, x0 + 3, y0 + 3, (treeListBox.ItemHeight - 9), (treeListBox.ItemHeight - 9)); g.DrawLine(p, x0 + 5, y0 + (treeListBox.ItemHeight - 3) / 2, x0 + (treeListBox.ItemHeight - 8), y0 + (treeListBox.ItemHeight - 3) / 2); if (!node.IsExpanded) { g.DrawLine(p, x0 + (treeListBox.ItemHeight - 3) / 2, y0 + 5, x0 + (treeListBox.ItemHeight - 3) / 2, y0 + (treeListBox.ItemHeight - 8)); } } } if (res != null) { int characters, lines; SizeF layoutArea = new SizeF(rect.Width, rect.Height); SizeF stringSize = g.MeasureString(res, fontToUse, layoutArea, sf, out characters, out lines); g.DrawString(res.Substring(0, characters) + (characters < res.Length ? "..." : ""), fontToUse, brush, rect.Location, sf); g.DrawLine(grayPen, rect.Right - 1, e.Bounds.Top, rect.Right - 1, e.Bounds.Bottom - 1); } position += c.Width; } g.Clip = oldClip; }
private void mainMenuItem_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { MainMenuItemDrawing.DrawMenuItem(e, (MenuItem)sender); }
/// <summary> /// Fancy tab coloring with ownerdraw to paint the callout buttons /// </summary> private void tc1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { try { //This line of code will help you to change the apperance like size,name,style. Font f; //For background color Brush backBrush = new System.Drawing.SolidBrush(MyColors.JColor[e.Index]); //For forground color Brush foreBrush = new SolidBrush(Color.Black); //This construct will hell you to deside which tab page have current focus //to change the style. if (e.Index == this.tc1.SelectedIndex) { //This line of code will help you to change the apperance like size,name,style. f = new Font(e.Font, FontStyle.Bold | FontStyle.Bold); f = new Font(e.Font, FontStyle.Bold); Rectangle tabRect = tc1.Bounds; Region tabRegion = new Region(tabRect); Rectangle TabItemRect = new Rectangle(0, 0, 0, 0); for (int nTanIndex = 0; nTanIndex < tc1.TabCount; nTanIndex++) { TabItemRect = Rectangle.Union(TabItemRect, tc1.GetTabRect(nTanIndex)); } tabRegion.Exclude(TabItemRect); e.Graphics.FillRegion(backBrush, tabRegion); } else { f = e.Font; foreBrush = new SolidBrush(e.ForeColor); } //To set the alignment of the caption. string tabName = this.tc1.TabPages[e.Index].Text; StringFormat sf = new StringFormat( ); sf.Alignment = StringAlignment.Center; //Thsi will help you to fill the interior portion of //selected tabpage. e.Graphics.FillRectangle(backBrush, e.Bounds); Rectangle r = e.Bounds; r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3); e.Graphics.DrawString(tabName, f, foreBrush, r, sf); sf.Dispose( ); if (e.Index == this.tc1.SelectedIndex) { f.Dispose( ); backBrush.Dispose( ); } else { backBrush.Dispose( ); foreBrush.Dispose( ); } } catch (Exception Ex) { MessageBox.Show(Ex.Message.ToString( ), "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Information); } }