/// <summary> /// Draw the command as a Button. /// </summary> /// <param name="g">Graphics reference used in calculations.</param> /// <param name="details">Source details needed to perform calculation.</param> /// <param name="drawRect">Bounding rectangle for drawing command.</param> /// <param name="state">State of the command to be drawn.</param> /// <param name="topLevel">Drawing as a top level item.</param> public override void Draw(Graphics g, ICommandDetails details, Rectangle drawRect, ItemState state, bool topLevel) { string drawText; CommandImage drawImage; // Decide if the Text of the button should be drawn if (details.ImageAndText == ImageAndText.ImageOnly) { drawText = string.Empty; } else { drawText = Text; } // Decide if the Image of the button should be drawn if (details.ImageAndText == ImageAndText.TextOnly) { drawImage = CommandImage.Empty; } else { drawImage = CommandImage; } // Use the provided layout direction by default LayoutDirection direction = details.Direction; // Do we need to override for drawing? if (details.OnlyHorizontalText) { direction = LayoutDirection.Horizontal; } // Use a helper method to draw command appropriately CommandDraw.DrawButtonCommand(g, details.Style, direction, drawRect, state, Enabled, details.TextEdge, details.Font, details.TextColor, details.BaseColor, drawText, drawImage, null, details.TrackBaseColor1, details.TrackBaseColor2, details.TrackLightColor1, details.TrackLightColor2, details.TrackLightLightColor1, details.TrackLightLightColor2, details.TrackDarkColor, _buttonStyle, _pushed, false, false); }
/// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { // Calculate the correct drawing state ItemState state; // If the mouse is over the button itself if (_mouseOver) { if (_mouseCapture) { state = ItemState.Pressed; } else { state = ItemState.HotTrack; } } else { if (_mouseCapture) { state = ItemState.HotTrack; } else { state = ItemState.Normal; } } // Draw the button using helper function CommandDraw.DrawButtonCommand(e.Graphics, _colorDetails.Style, _direction, ClientRectangle, state, (AlwaysDrawEnabled ? true : Enabled), _textEdge, Font, ForeColor, _colorDetails.BaseColor, Text, _image, _imageAttr, _colorDetails.TrackBaseColor1, _colorDetails.TrackBaseColor2, _colorDetails.TrackLightColor1, _colorDetails.TrackLightColor2, _colorDetails.TrackLightLightColor1, _colorDetails.TrackLightLightColor2, _colorDetails.TrackDarkColor, _buttonStyle, _pushed, _staticIDE, AlwaysDrawBorder); base.OnPaint(e); }