public static void DrawImage(Graphics g, string imageFileName, Rectangle rect, Point offSet) { string prefix = "icons."; //folder in project where the bitmaps are located string bitmapName = prefix + imageFileName; iconPainter.PaintIcon(g, rect, offSet, bitmapName, Color.Black); }
// Used for drawing new customized button control public override void Draw(Graphics g, int rowIndex, int colIndex, bool bActive, GridStyleInfo style) { base.Draw(g, rowIndex, colIndex, bActive, style); // draw the button bool hovering = IsHovering(rowIndex, colIndex); bool mouseDown = IsMouseDown(rowIndex, colIndex); bool disabled = !style.Clickable; ButtonState buttonState = ButtonState.Normal; if (disabled) { buttonState |= ButtonState.Inactive | ButtonState.Flat; } else if (!hovering && !mouseDown) { buttonState |= ButtonState.Flat; } Point ptOffset = Point.Empty; if (mouseDown) { ptOffset = new Point(1, 1); buttonState |= ButtonState.Pushed; } DrawButton(g, Bounds, buttonState, style); Image img = Image.FromFile(@"..\\..\\Images\delete.png"); Bitmap bmp = img as Bitmap; Rectangle r = iconPainter.PaintIcon(g, Bounds, ptOffset, bmp, Color.Black); }
/// <override/> public override void Draw(Graphics g, int rowIndex, int colIndex, bool bActive, GridStyleInfo style) { // draw the button bool isHovering = IsHovering(rowIndex, colIndex); bool isMouseDown = IsMouseDown(rowIndex, colIndex); Node n = helper.GetNode(rowIndex); if (!n.HasChildren) { return; } bool expanded = n.IsExpanded; bool disabled = !style.Clickable; Rectangle rect = Bounds; string bitmapName = ""; if (disabled) { bitmapName = "SFEXPANDING.BMP"; } else if (!isHovering && !isMouseDown) { if (!expanded) { bitmapName = "SFEXPAND.BMP"; } else { bitmapName = "SFCOLLAPSE.BMP"; } } else { if (!expanded) { bitmapName = "SFEXPANDING.BMP"; } else { bitmapName = "SFCOLLAPSING.BMP"; } } iconPainter.PaintIcon(g, rect, Point.Empty, bitmapName, Color.Black); }
/// <override/> public override void Draw(Graphics g, int rowIndex, int colIndex, bool bActive, GridStyleInfo style) { TraceUtil.TraceCurrentMethodInfo(rowIndex, colIndex, bActive, style.CellValue); base.Draw(g, rowIndex, colIndex, bActive, style); // draw the button bool hovering = IsHovering(rowIndex, colIndex); bool mouseDown = IsMouseDown(rowIndex, colIndex); bool disabled = !style.Clickable; ButtonState buttonState = ButtonState.Normal; if (disabled) { buttonState |= ButtonState.Inactive | ButtonState.Flat; } else if (!hovering && !mouseDown) { buttonState |= ButtonState.Flat; } Point ptOffset = Point.Empty; if (mouseDown) { ptOffset = new Point(1, 1); buttonState |= ButtonState.Pushed; } DrawButton(g, Bounds, buttonState, style); string bitmapName = "Browse.bmp"; // make sure this is included in project and marked as "Embedded Resource" // Instead of using GridIconPaint you could simple use Image.Draw here // with an existing bitmap. GridIconPaint is convenient because it lets // us easily draw over existing background and replace the black color // in the bitmap with a different color. iconPainter.PaintIcon(g, Bounds, ptOffset, bitmapName, Color.White); }
public override void Draw(Graphics g, int rowIndex, int colIndex, bool bActive, GridStyleInfo style) { TraceUtil.TraceCurrentMethodInfo(rowIndex, colIndex, bActive, style.CellValue); base.Draw(g, rowIndex, colIndex, bActive, style); bool hovering = IsHovering(rowIndex, colIndex); bool mouseDown = IsMouseDown(rowIndex, colIndex); bool disabled = !style.Clickable; ButtonState buttonState = ButtonState.Normal; if (disabled) { buttonState |= ButtonState.Inactive | ButtonState.Flat; } else if (!hovering && !mouseDown) { buttonState |= ButtonState.Flat; } Point ptOffset = Point.Empty; if (mouseDown) { ptOffset = new Point(1, 1); buttonState |= ButtonState.Pushed; } DrawButton(g, Bounds, buttonState, style); Bitmap bitmapName = new Bitmap(Image.FromFile(@"..\..\Browse.bmp")); icon.PaintIcon(g, Bounds, ptOffset, bitmapName, Color.White); }
/// <summary> /// Draws the default button face /// </summary> /// <param name="g">The <see cref="System.Drawing.Graphics"/> context of the canvas.</param> /// <param name="buttonState">A <see cref="ButtonState"/> that specifies the current state.</param> /// <param name="style">The <see cref="GridStyleInfo"/> object that holds cell information.</param> public void DrawDefaultButtonFace(Graphics g, ButtonState buttonState, GridStyleInfo style) { // Set the button style properties ButtonEditStyleProperties sp = new ButtonEditStyleProperties(style); //Button bounds Rectangle rect = Bounds; Rectangle faceRect = Rectangle.FromLTRB(rect.Left + 1, rect.Top + 1, rect.Right - 2, rect.Bottom - 2); bool disabled = !sp.ButtonEditInfo.Enabled; bool drawPressed = (buttonState & ButtonState.Pushed) != 0; //Determine the Offset Point ptOffset = Point.Empty; if (drawPressed) { ptOffset = new Point(1, 1); } // Draws the image based on ButtonEditInfo.ButtonEditType string resourceName; if (sp.ButtonEditInfo.ButtonEditType != ButtonType.None) { switch (sp.ButtonEditInfo.ButtonEditType) { case ButtonType.Browse: resourceName = "Browse.bmp"; break; case ButtonType.Check: resourceName = "Check.bmp"; break; case ButtonType.Down: resourceName = "Down.bmp"; break; case ButtonType.Left: resourceName = "Left.bmp"; break; case ButtonType.Leftend: resourceName = "Leftend.bmp"; break; case ButtonType.Redo: resourceName = "Redo.bmp"; break; case ButtonType.Right: resourceName = "Right.bmp"; break; case ButtonType.Rightend: resourceName = "Rightend.bmp"; break; case ButtonType.Undo: resourceName = "Undo.bmp"; break; case ButtonType.Up: resourceName = "Up.bmp"; break; default: resourceName = "Browse.bmp"; break; } // Draws the image from ButtonEditInfo.Image if (sp.ButtonEditInfo.ButtonEditType == ButtonType.Image) { if (sp.ButtonEditInfo.Image != null) { if (!drawPressed) { DrawingUtils.DrawImage(g, sp.ButtonEditInfo.Image as Image, Bounds.X + 2, Bounds.Y + 2, Bounds.Width - 4, Bounds.Height - 4); } else { DrawingUtils.DrawImage(g, sp.ButtonEditInfo.Image as Image, Bounds.X + 1, Bounds.Y + 1, Bounds.Width - 4, Bounds.Height - 4); } } return; } string prefix = "ButtonImages."; string bitmapName = prefix + resourceName; // Instead of using GridIconPaint you could simple use Image.Draw here // with an existing bitmap. GridIconPaint is convenient because it lets // us easily draw over existing background and replace the black color // in the bitmap with a different color. iconPainter.PaintIcon(g, Bounds, ptOffset, bitmapName, Color.Black); return; } // Colored button drawing Color hilight = SystemColors.ControlLightLight; Color shadow = SystemColors.ControlDarkDark; Color draw = sp.ButtonEditInfo.BackColor; Brush br = new SolidBrush(draw); // Colors the button only if the ForceBackColor is set (themes application) if (sp.ButtonEditInfo.ForceBackColor) { if (!disabled) { if (!drawPressed) { g.FillRectangle(br, Bounds); if (buttonState == ButtonState.Flat) { ControlPaint.DrawBorder(g, Bounds, SystemColors.ControlDark, ButtonBorderStyle.Solid); } else { GridUtil.Draw3dFrame(g, rect.Left, rect.Top, rect.Right - 1, rect.Bottom - 1, 1, hilight, shadow); } } else { g.FillRectangle(br, new Rectangle(Bounds.X + 1, Bounds.Y + 1, Bounds.Width, Bounds.Height)); GridUtil.Draw3dFrame(g, rect.Left - 1, rect.Top - 1, rect.Right, rect.Bottom, 1, hilight, shadow); br.Dispose(); } } } // Draw the button text string text = sp.ButtonEditInfo.Text; if (text != null && text.Length > 0) { Font font = style.GdipFont; StringFormat format = new StringFormat(); bool isRightToLeft = false; if (this.Grid.RightToLeft == RightToLeft.Inherit && Grid.IsRightToLeft() || style.RightToLeft == RightToLeft.Yes) { isRightToLeft = true; } if (isRightToLeft) { format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.HotkeyPrefix = style.HotkeyPrefix; format.Trimming = style.Trimming; if (!style.WrapText) { format.FormatFlags = StringFormatFlags.NoWrap; } Color textColor = Grid.PrintingMode && Grid.Model.Properties.BlackWhite ? Color.Black : sp.ButtonEditInfo.TextColor; if (disabled) { DrawText(g, sp.ButtonEditInfo.Text, font, faceRect, style, textColor, true, isRightToLeft); } else { if (!drawPressed) { if (buttonState == ButtonState.Flat) { DrawText(g, sp.ButtonEditInfo.Text, font, new Rectangle(faceRect.Left, faceRect.Top, faceRect.Width, faceRect.Height), style, textColor, false, isRightToLeft); } else { DrawText(g, sp.ButtonEditInfo.Text, font, new Rectangle(faceRect.Left + 1, faceRect.Top + 1, faceRect.Width, faceRect.Height), style, textColor, false, isRightToLeft); } } else { DrawText(g, sp.ButtonEditInfo.Text, font, faceRect, style, textColor, false, isRightToLeft); } } format.Dispose(); } }