/// <summary> /// Draws the button onto the specified Graphics object. /// </summary> /// <param name="gfx">The graphics object to draw on.</param> /// <param name="defaultBackColor">The default background /// colour to use when drawing the button.</param> /// <param name="controlEnabled">Whether the control is enabled or not.</param> public override void DrawItem( Graphics gfx, Color defaultBackColor, bool controlEnabled ) { Color backColor = defaultBackColor; if (owner != null) { VSNetListBarGroup selGroup = owner.SelectedGroup; if (selGroup != null) { if (ButtonType == ListBarScrollButtonType.Up) { backColor = selGroup.BackColor; } else { VSNetListBarGroup nextGroup = null; for (int i = owner.Groups.IndexOf(selGroup) + 1; i < owner.Groups.Count; i++) { if (owner.Groups[i].Visible) { nextGroup = owner.Groups[i]; break; } } if (nextGroup != null) { backColor = nextGroup.BackColor; } } } } Brush br = new SolidBrush(backColor); gfx.FillRectangle(br, Rectangle); br.Dispose(); // in VS.NET bar the item is always drawn. When // it's not "Visible" then it is drawn disabled: VSNetListBarUtility.DrawScrollButton( gfx, Rectangle, backColor, (MouseDown && MouseOver), (Visible && controlEnabled), (ButtonType != ListBarScrollButtonType.Up)); }
/// <summary> /// Draws this item into the specified graphics object. /// </summary> /// <param name="gfx">The graphics object to draw onto.</param> /// <param name="ils">The ImageList to source icons from.</param> /// <param name="defaultFont">The default font to use to draw the button.</param> /// <param name="style">The style (Outlook version) to draw using.</param> /// <param name="view">The view (large or small icons) to draw using.</param> /// <param name="scrollOffset">The offset of the first item from the /// (0,0) point in the graphics object.</param> /// <param name="skipDrawText">Whether to skip drawing text or not /// (the item is being edited)</param> /// <param name="controlEnabled">Whether the control is enabled or not.</param> public override void DrawButton( Graphics gfx, ImageList ils, Font defaultFont, ListBarDrawStyle style, ListBarGroupView view, int scrollOffset, bool controlEnabled, bool skipDrawText ) { bool rightToLeft = false; Font drawFont = Font; if (drawFont == null) { drawFont = defaultFont; } Color backColor = Color.FromKnownColor(KnownColor.Control); if (Owner != null) { if (Owner.RightToLeft == RightToLeft.Yes) { rightToLeft = true; } backColor = Owner.BackColor; } Rectangle drawRect = new Rectangle(Location, new Size(Width, Height)); drawRect.Offset(0, scrollOffset); if (((Selected) && (!MouseOver)) || (MouseOver && MouseDown)) { // Draw the background: VSNetListBarUtility.DrawSelectedItemBackground(gfx, drawRect); } Rectangle itemRect = drawRect; itemRect.Inflate(-1, -1); if ((Selected) || (MouseDown && MouseOver)) { itemRect.Offset(1, 1); } RectangleF textRect; // Draw the icon: if (rightToLeft) { iconRectangle = new Rectangle( itemRect.Right - ils.ImageSize.Width - 4, itemRect.Top + (itemRect.Height - ils.ImageSize.Height) / 2, ils.ImageSize.Width, ils.ImageSize.Height); textRect = new RectangleF( itemRect.Left, itemRect.Top, itemRect.Width - (ils.ImageSize.Width - 6), itemRect.Height); } else { iconRectangle = new Rectangle( itemRect.Left + 4, itemRect.Top + (itemRect.Height - ils.ImageSize.Height) / 2, ils.ImageSize.Width, ils.ImageSize.Height); textRect = new RectangleF( itemRect.Left + ils.ImageSize.Height + 6, itemRect.Top, itemRect.Width - (ils.ImageSize.Width - 6), itemRect.Height); } if (IconIndex <= ils.Images.Count) { if (Enabled && controlEnabled) { ils.Draw(gfx, iconRectangle.Left, iconRectangle.Top, IconIndex); } else { System.Windows.Forms.ControlPaint.DrawImageDisabled(gfx, ils.Images[IconIndex], iconRectangle.Left, iconRectangle.Top, backColor); } } if ((view == ListBarGroupView.SmallIconsOnly) || (view == ListBarGroupView.LargeIconsOnly)) { textRectangle = new Rectangle(0, 0, 0, 0); skipDrawText = true; } if (!skipDrawText) { // Draw the text: StringFormat format = new StringFormat(StringFormatFlags.LineLimit | (rightToLeft ? StringFormatFlags.DirectionRightToLeft : 0)); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisWord; if (Enabled && controlEnabled) { Brush br = new SolidBrush(ForeColor); gfx.DrawString(Caption, drawFont, br, textRect, format); br.Dispose(); } else { Brush br = new SolidBrush(CustomBorderColor.ColorLightLight(backColor)); textRect.Offset(1F, 1F); gfx.DrawString(Caption, drawFont, br, textRect, format); br.Dispose(); textRect.Offset(-1F, -1F); br = new SolidBrush(CustomBorderColor.ColorDark(backColor)); gfx.DrawString(Caption, drawFont, br, textRect, format); br.Dispose(); } format.Dispose(); textRectangle = new Rectangle((int)textRect.Left, (int)textRect.Top, (int)textRect.Width, (int)textRect.Height); // TODO_ If mouse over and text too wide show the popup. // Currently a problem with my popup code in that it // foils the Framework's WM_NCACTIVATE processing which // results in spurious focus/mouse over events... } // Draw the border: if (((MouseOver) || (Selected)) && (Enabled)) { CustomBorderColor.DrawBorder(gfx, drawRect, backColor, true, ((MouseDown && MouseOver) || (Selected))); } }