/// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs that contains the event data.</param> protected override void OnPaint(PaintEventArgs args) { // Call the base class's method so that registered delegates receive the event. base.OnPaint(args); // Fix bug 602576: The 'Remove Effects' button is truncated in right-to-left builds if (BidiHelper.IsRightToLeft) args.Graphics.ResetClip(); // Take int account vertical padding Rectangle rect = new Rectangle(VirtualClientRectangle.X, VirtualClientRectangle.Y + VerticalPadding, VirtualClientRectangle.Width, VirtualClientRectangle.Height); BidiGraphics g = new BidiGraphics(args.Graphics, rect); // No painting required if there is no parent or no command. if (Parent == null || Command == null) return; // Determine the draw state of the button. DrawState drawState; if (!Command.Enabled) drawState = DrawState.Disabled; else if (Command.Latched || (ButtonPushed && MouseInside) || (ContextMenuUserInterface && ContextMenuShowing)) drawState = DrawState.Pushed; else if (MouseInside || (DropDownContextMenuUserInterface && ContextMenuShowing)) drawState = DrawState.Selected; else drawState = DrawState.Enabled; // Draw the button. if (Command.CommandBarButtonStyle == CommandBarButtonStyle.System) { Size imageSize = ImageSize; // is this a large button? bool isLargeButton = false; if (imageSize.Height > SystemButtonHelper.SMALL_BUTTON_IMAGE_SIZE) isLargeButton = true; if (Command is ICustomButtonBitmapPaint) { switch (drawState) { case DrawState.Selected: SystemButtonHelper.DrawSystemButtonFace(g, DropDownContextMenuUserInterface, contextMenuShowing, VirtualClientRectangle, isLargeButton); break; case DrawState.Pushed: SystemButtonHelper.DrawSystemButtonFacePushed(g, DropDownContextMenuUserInterface, VirtualClientRectangle, isLargeButton); break; } ((ICustomButtonBitmapPaint)Command).Paint(g, rImage, drawState); } else { Bitmap buttonBitmap = null; switch (drawState) { case DrawState.Disabled: buttonBitmap = Command.CommandBarButtonBitmapDisabled; break; case DrawState.Enabled: buttonBitmap = Command.CommandBarButtonBitmapEnabled; break; case DrawState.Selected: SystemButtonHelper.DrawSystemButtonFace(g, DropDownContextMenuUserInterface, contextMenuShowing, VirtualClientRectangle, isLargeButton); buttonBitmap = Command.CommandBarButtonBitmapSelected; break; case DrawState.Pushed: SystemButtonHelper.DrawSystemButtonFacePushed(g, DropDownContextMenuUserInterface, VirtualClientRectangle, isLargeButton); buttonBitmap = Command.CommandBarButtonBitmapSelected; break; } // Draw the button bitmap. if (buttonBitmap != null && !Command.SuppressCommandBarBitmap) { if (!SystemInformation.HighContrast) g.DrawImage(false, buttonBitmap, rImage); else { //apply a high contrast image matrix ImageAttributes ia = new ImageAttributes(); ia.SetColorMatrix(HighContrastColorMatrix); ColorMap cm = new ColorMap(); cm.OldColor = Color.White; cm.NewColor = SystemColors.Control; ia.SetRemapTable(new ColorMap[] { cm }); g.DrawImage(false, buttonBitmap, rImage, 0, 0, buttonBitmap.Width, buttonBitmap.Height, GraphicsUnit.Pixel, ia); } } } // Draw the text. if (Command.CommandBarButtonText != null && Command.CommandBarButtonText.Length != 0) { Color textColor; if (drawState == DrawState.Disabled) textColor = commandBarLightweightControl.DisabledTextColor; else textColor = commandBarLightweightControl.TextColor; g.DrawText( Command.CommandBarButtonText, ApplicationManager.ApplicationStyle.NormalApplicationFont, rText, textColor, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.NoPadding | TextFormatFlags.NoClipping); } // Draw the context menu arrow, if needed. if (DropDownContextMenuUserInterface || ContextMenuUserInterface) { Bitmap contextMenuArrowBitmapToDraw; if (drawState == DrawState.Disabled) contextMenuArrowBitmapToDraw = contextMenuArrowBitmapDisabled; else contextMenuArrowBitmapToDraw = contextMenuArrowBitmap; int height = isLargeButton ? SystemButtonHelper.LARGE_BUTTON_TOTAL_SIZE : VirtualHeight; g.DrawImage(false, contextMenuArrowBitmapToDraw, rArrow); } } else if (Command.CommandBarButtonStyle == CommandBarButtonStyle.Bitmap) { switch (drawState) { case DrawState.Disabled: g.DrawImage(true, Command.CommandBarButtonBitmapDisabled, HorizontalMargin, TOP_MARGIN); break; case DrawState.Enabled: g.DrawImage(true, Command.CommandBarButtonBitmapEnabled, HorizontalMargin, TOP_MARGIN); break; case DrawState.Selected: g.DrawImage(true, Command.CommandBarButtonBitmapSelected, HorizontalMargin, TOP_MARGIN); break; case DrawState.Pushed: g.DrawImage(true, Command.CommandBarButtonBitmapPushed, HorizontalMargin, TOP_MARGIN); break; } } else if (Command.CommandBarButtonStyle == CommandBarButtonStyle.Provider) { DrawProviderButtonFace(g, drawState); DrawProviderButton(g, drawState); } if (Focused) g.DrawFocusRectangle(new Rectangle(0, 0, VirtualWidth, VirtualHeight), Parent.ForeColor, Parent.BackColor); }