/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="paintParams"/> is <see langword="null"/>.</para> /// </exception> public void DrawCloseButton(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; NuGenControlState state = paintParams.State; Image imageToDraw = null; switch (state) { case NuGenControlState.Hot: { imageToDraw = Resources.Image_CloseButton_Hot; break; } case NuGenControlState.Pressed: { imageToDraw = Resources.Image_CloseButton_Pressed; break; } default: { imageToDraw = Resources.Image_CloseButton_Normal; break; } } if (state == NuGenControlState.Disabled) { ControlPaint.DrawImageDisabled(g, imageToDraw, bounds.X, bounds.Y, SystemColors.Control); } else { g.DrawImageUnscaled(imageToDraw, bounds.X, bounds.Y); } }
private void PaintTextandImage(Graphics g, Rectangle bounds) { // Figure out where our text and image should go CalculateButtonTextAndImageLayout(ref bounds, out var text_rectangle, out var image_rectangle); // draw the image if (Image != null) { if (Enabled) { g.DrawImage(Image, image_rectangle.X, image_rectangle.Y, Image.Width, Image.Height); } else { ControlPaint.DrawImageDisabled(g, Image, image_rectangle.X, image_rectangle.Y, BackColor); } } // If we dont' use mnemonic, set formatFlag to NoPrefix as this will show ampersand. if (!UseMnemonic) { _textFormatFlags = _textFormatFlags | TextFormatFlags.NoPrefix; } else if (!ShowKeyboardCues) { _textFormatFlags = _textFormatFlags | TextFormatFlags.HidePrefix; } // draw the text if (!string.IsNullOrEmpty(Text)) { if (Enabled) { TextRenderer.DrawText(g, Text, Font, text_rectangle, ForeColor, _textFormatFlags); } else { ControlPaint.DrawStringDisabled(g, Text, Font, BackColor, text_rectangle, _textFormatFlags); } } }
private void DrawButton(GraphicsCache cache, Rectangle bounds, ActiveLookAndFeelStyle lookAndFeel, AppearanceObject appearance, ObjectState state, string caption, bool drawIcon) { EditorButtonObjectInfoArgs args = new EditorButtonObjectInfoArgs(cache, Button, appearance); BaseLookAndFeelPainters painters = LookAndFeelPainterHelper.GetPainter(lookAndFeel); // Create some margin bounds.Inflate(-BUTTONMARGIN, -BUTTONMARGIN); args.Bounds = bounds; args.State = state; painters.Button.DrawObject(args); if (drawIcon) { Image calcIcon = Microsoft.Dynamics.Retail.Pos.Dialog.Properties.Resources.PriceCalc; if (calcIcon != null) { // Determine origin point to draw centered int x = args.Bounds.Left + ((args.Bounds.Width - calcIcon.Width) / 2); int y = args.Bounds.Top + ((args.Bounds.Height - calcIcon.Height) / 2); if (state == ObjectState.Disabled) { ControlPaint.DrawImageDisabled(cache.Graphics, calcIcon, x, y, Color.Transparent); } else { cache.Graphics.DrawImageUnscaled(calcIcon, x, y); } } } else { // Draw the text // DO NOT dispose of the brush, as it is owned by the cache Brush brush = GetButtonForeBrush(state, cache); StringFormat sf = appearance.GetStringFormat(appearance.GetTextOptions()); painters.Button.DrawCaption(args, caption, appearance.Font, brush, args.Bounds, sf); } }
/// <summary> /// Raises the PaintBackground event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> protected override void OnPaintBackground(PaintCellEventArgs e) { base.OnPaintBackground(e); // don't bother if the Cell is null if (e.Cell == null) { return; } // fill the client area with the window color (this // will be the background color of the progress bar) e.Graphics.FillRectangle(SystemBrushes.Window, this.ClientRectangle); Rectangle progressRect = this.ClientRectangle; // draw the border if (e.Enabled) { // if xp themes are enabled, shrink the size of the // progress bar as otherwise the focus rect appears // to go awol if the cell has focus if (ThemeManager.VisualStylesEnabled) { progressRect.Inflate(-1, -1); } ThemeManager.DrawProgressBar(e.Graphics, progressRect); } else { using (Bitmap b = new Bitmap(progressRect.Width, progressRect.Height)) { using (Graphics g = Graphics.FromImage(b)) { ThemeManager.DrawProgressBar(g, new Rectangle(0, 0, progressRect.Width, progressRect.Height)); } ControlPaint.DrawImageDisabled(e.Graphics, b, progressRect.X, progressRect.Y, this.BackBrush.Color); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draws the button with an image. /// </summary> /// ------------------------------------------------------------------------------------ private void DrawWithImage(PaintEventArgs e) { if (Image == null) { return; } int x = (Width - Image.Width) / 2; int y = (Height - Image.Height) / 2; var rc = new Rectangle(x, y, Image.Width, Image.Height); if (Enabled) { e.Graphics.DrawImageUnscaledAndClipped(Image, rc); } else { ControlPaint.DrawImageDisabled(e.Graphics, Image, x, y, SystemColors.Control); } }
protected void DrawImage(Graphics g, DrawState state, Image image, int x, int y) { SizeF sizeF = Image.PhysicalDimension; int imageWidth = (int)sizeF.Width; int imageHeight = (int)sizeF.Height; if (state == DrawState.Normal) { g.DrawImage(Image, x, y, imageWidth, imageHeight); } else if (state == DrawState.Disable) { ControlPaint.DrawImageDisabled(g, Image, x, y, SystemColors.Control); } else if (state == DrawState.Pressed || state == DrawState.Hot) { ControlPaint.DrawImageDisabled(g, Image, x + 1, y, SystemColors.Control); g.DrawImage(Image, x, y - 1, imageWidth, imageHeight); } }
private void DrawImage(PaintEventArgs e) { if (this.image != null) { if (this.Enabled) { e.Graphics.DrawImage(this.image, this.imageBounds); } else { using (Bitmap bitmap = new Bitmap(this.imageBounds.Width, this.imageBounds.Height)) { using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.DrawImage(this.image, 0, 0, this.imageBounds.Width, this.imageBounds.Height); } ControlPaint.DrawImageDisabled(e.Graphics, bitmap, this.imageBounds.X, this.imageBounds.Y, Color.Transparent); } } } }
public override void OutputResource(string name, string extension, HttpListenerContext context) { Image image = null; if (name.EndsWith("_disabled")) { name = name.Substring(0, name.Length - 9); if (!mDisabledImages.TryGetValue(name, out image)) { Image srcImage = mResourceManager.GetObject(name) as Image; if (srcImage != null) { Image disabledImage = srcImage.Clone() as Image; using (Graphics disabledImageGraphics = Graphics.FromImage(disabledImage)) { disabledImageGraphics.Clear(Color.Transparent); ControlPaint.DrawImageDisabled(disabledImageGraphics, srcImage, 0, 0, Color.White); mDisabledImages[name] = disabledImage; // Cache for later image = disabledImage; } } } } else { image = mResourceManager.GetObject(name) as Image; } if (image == null) { context.Response.StatusCode = 404; return; } MemoryStream stream = new MemoryStream(); image.Save(stream, GetImageFormat(extension)); byte[] buffer = stream.GetBuffer(); context.Response.ContentType = string.Format("img/{0}", extension); context.Response.ContentLength64 = buffer.Length; context.Response.OutputStream.Write(buffer, 0, buffer.Length); }
void DrawIcon(Graphics g, Image icon, Rectangle bounds, bool selected, bool enabled, bool isChecked) { // make icon transparent Bitmap tempIcon = ( Bitmap )icon; tempIcon.MakeTransparent(iconTransparentColor); int iconTop = bounds.Top + (itemHeight - BITMAP_SIZE) / 2; int iconLeft = bounds.Left + (STRIPE_WIDTH - BITMAP_SIZE) / 2; if (enabled) { if (selected) { if (isChecked) { DrawCheckedRectangle(g, bounds); g.DrawImage(icon, iconLeft + 1, iconTop); } else { ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, Color.Black); g.DrawImage(icon, iconLeft, iconTop - 1); } } else { if (isChecked) { DrawCheckedRectangle(g, bounds); } g.DrawImage(icon, iconLeft + 1, iconTop); } } else { ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, SystemColors.HighlightText); } }
private void PaintTextandImage(Graphics g, Rectangle bounds) { // Figure out where our text and image should go Rectangle text_rectangle; Rectangle image_rectangle; CalculateButtonTextAndImageLayout(ref bounds, out text_rectangle, out image_rectangle); //draw the image if (Image != null) { if (Enabled) { g.DrawImage(Image, image_rectangle.X, image_rectangle.Y, Image.Width, Image.Height); } else { ControlPaint.DrawImageDisabled(g, Image, image_rectangle.X, image_rectangle.Y, BackColor); } } }
public void Paint(Graphics g, Rectangle r, ImageList list, Color bg) { if (style == FlatButtonType.Control) { return; } if (style == FlatButtonType.Line) { g.DrawLine(Pens.DarkGray, r.X + 2, r.Top, r.X + 2, r.Bottom - 1); } else { if (style == FlatButtonType.RadioDown) { g.FillRectangle(Brushes.Lavender, r.X, r.Y, r.Width - 1, r.Height - 1); bg = Color.Lavender; } else if (state != FlatButtonState.Basic) { g.FillRectangle(state == FlatButtonState.Hover ? Brushes.LightSteelBlue : Brushes.SteelBlue, r.X, r.Y, r.Width - 1, r.Height - 1); bg = state == FlatButtonState.Hover ? Color.LightSteelBlue : Color.SteelBlue; } if (style == FlatButtonType.RadioDown || state != FlatButtonState.Basic) { g.DrawRectangle(Pens.DarkBlue, r.Left, r.Top, r.Width - 1, r.Height - 1); } int hover = state == FlatButtonState.Hover ? 1 : 0; if (disabled) { ControlPaint.DrawImageDisabled(g, list.Images[image_index], r.X + 3 - hover, r.Y + 3 - hover, bg); } else { list.Draw(g, r.X + 3 - hover, r.Y + 3 - hover, 16, 16, image_index); } } }
/* * OnPaint */ /// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"></see> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Image imageToDraw = null; using (Pen pen = new Pen(this.BackColor)) { g.DrawRectangle(pen, this.ClientRectangle); } switch (this.ButtonStateTracker.GetControlState(this)) { case NuGenControlState.Hot: { imageToDraw = Resources.CloseButton_Hot; break; } case NuGenControlState.Pressed: { imageToDraw = Resources.CloseButton_Pressed; break; } default: { imageToDraw = Resources.CloseButton_Normal; break; } } if (this.Enabled) { g.DrawImageUnscaled(imageToDraw, this.DisplayRectangle.Location); } else { ControlPaint.DrawImageDisabled(g, imageToDraw, 0, 0, SystemColors.Control); } }
void DrawButtonWithoutVisualStyles(PaintEventArgs e) { ControlPaint.DrawButton(e.Graphics, HeaderRect, ButtonState); if (Enabled) { using var textBrush = new SolidBrush(ForeColor); e.Graphics.DrawString(Text, Font, textBrush, TextRect); e.Graphics.DrawImageUnscaledAndClipped(ButtonImage, ImageRect); } else { using var format = GetStringFormat(); ControlPaint.DrawStringDisabled(e.Graphics, Text, Font, BackColor, TextRect, format); ControlPaint.DrawImageDisabled(e.Graphics, ButtonImage, ImageRect.Left, ImageRect.Top, BackColor); } if (Focused && ShowFocusCues) { ControlPaint.DrawFocusRectangle(e.Graphics, FocusRect); } }
void DrawMenuGlyph(Graphics g, Rectangle bounds, bool selected, bool bCheckMark) { int checkTop = bounds.Top + (itemHeight - BITMAP_SIZE) / 2; int checkLeft = bounds.Left + (STRIPE_WIDTH - BITMAP_SIZE) / 2; if (Enabled) { g.FillRectangle((selected == true) ? brushDarkSelct : brushSelection, bounds.Left + 1, bounds.Top + 1, STRIPE_WIDTH - 3, bounds.Height - 3); glyphsImages.Draw(g, checkLeft, checkTop, bCheckMark?0:1); g.DrawRectangle(new Pen(borderColor), bounds.Left + 1, bounds.Top + 1, STRIPE_WIDTH - 3, bounds.Height - 3); } else { int imageIndex = (bCheckMark == true) ? 0 : 1; ControlPaint.DrawImageDisabled(g, glyphsImages.Images[imageIndex], checkLeft, checkTop, Color.Black); } }
private void DrawIcon(Graphics g, Image icon, Rectangle bounds, bool selected, bool enabled, bool ischecked) { int iconTop = bounds.Top + (itemHeight - BITMAP_SIZE) / 2; int iconLeft = bounds.Left + (STRIPE_WIDTH - BITMAP_SIZE) / 2; if (enabled) { if (selected) { ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, Color.Black); g.DrawImage(icon, iconLeft, iconTop - 1); } else { g.DrawImage(icon, iconLeft + 1, iconTop); } } else { ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, SystemColors.HighlightText); } }
private void DrawDisbledGlyph() { if (expandGlyph != null) { if (disabledGlyph == null || disabledGlyph.Size != expandGlyph.Size || disabledGlyphBackColor != BackColor || !string.Equals(previousDisabledGlyphResourceName, disabledGlyphResourceName, StringComparison.Ordinal)) { disabledGlyph?.Dispose(); disabledGlyph = new Bitmap(expandGlyph.Width, expandGlyph.Height, PixelFormat.Format32bppArgb); disabledGlyphBackColor = BackColor; previousDisabledGlyphResourceName = disabledGlyphResourceName; using (Graphics graphics = Graphics.FromImage(disabledGlyph)) { ControlPaint.DrawImageDisabled(graphics, expandGlyph, 0, 0, disabledGlyphBackColor); } } } }
protected override void OnPaint(PaintEventArgs e) { DrawBackground(e.Graphics); Point point = new Point { X = (this.Width - this.Image.Width) / 2, Y = (this.Height - this.Image.Height) / 2 }; if (this.Enabled) { if (this.drawState == ButtonDrawState.Pressed) { point.Offset(1, 1); } if (this.image != null) { e.Graphics.DrawImage(this.image, point); } if (this.drawState == ButtonDrawState.Focused) { DrawFocusRectangle(e.Graphics); } } else { if (this.image != null) { ControlPaint.DrawImageDisabled(e.Graphics, this.image, point.X, point.Y, this.BackColor); } } base.OnPaint(e); }
private void DrawImage(Graphics g) { Image image = this.Enabled ? ImageEnabled : ((ImageDisabled != null) ? ImageDisabled : ImageEnabled); ImageAttributes imageAttr = null; if (null == image) { return; } if (m_monochrom) { imageAttr = new ImageAttributes(); // transform the monochrom image // white -> BackColor // black -> ForeColor ColorMap[] colorMap = new ColorMap[2]; colorMap[0] = new ColorMap(); colorMap[0].OldColor = Color.White; colorMap[0].NewColor = this.BackColor; colorMap[1] = new ColorMap(); colorMap[1].OldColor = Color.Black; colorMap[1].NewColor = this.ForeColor; imageAttr.SetRemapTable(colorMap); } Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); if ((!Enabled) && (null == ImageDisabled)) { using (Bitmap bitmapMono = new Bitmap(image, ClientRectangle.Size)) { if (imageAttr != null) { using (Graphics gMono = Graphics.FromImage(bitmapMono)) { gMono.DrawImage(image, new Point[3] { new Point(0, 0), new Point(image.Width - 1, 0), new Point(0, image.Height - 1) }, rect, GraphicsUnit.Pixel, imageAttr); } } ControlPaint.DrawImageDisabled(g, bitmapMono, 0, 0, this.BackColor); } } else { // Three points provided are upper-left, upper-right and // lower-left of the destination parallelogram. Point[] pts = new Point[3]; pts[0].X = (Enabled && m_mouseOver && m_mouseCapture) ? 1 : 0; pts[0].Y = (Enabled && m_mouseOver && m_mouseCapture) ? 1 : 0; pts[1].X = pts[0].X + ClientRectangle.Width; pts[1].Y = pts[0].Y; pts[2].X = pts[0].X; pts[2].Y = pts[1].Y + ClientRectangle.Height; if (imageAttr == null) { g.DrawImage(image, pts, rect, GraphicsUnit.Pixel); } else { g.DrawImage(image, pts, rect, GraphicsUnit.Pixel, imageAttr); } } }
internal void Draw(Graphics e, DateItem queryInfo) { StringFormat dateAlign = new StringFormat(); StringFormat textAlign = new StringFormat(); Font boldFont = new Font(m_month.DateFont.Name, m_month.DateFont.Size, m_month.DateFont.Style | FontStyle.Bold); Color bgColor1 = m_month.Colors.Days.BackColor1; Color bgColor2 = m_month.Colors.Days.BackColor2; mcGradientMode gradientMode = m_month.Colors.Days.GradientMode; Color textColor = m_month.Colors.Days.Text; Color dateColor = m_month.Colors.Days.Date; Brush dateBrush = new SolidBrush(dateColor); Brush textBrush = new SolidBrush(textColor); Brush bgBrush = new SolidBrush(bgColor1); string dateString; m_imageRect = new Rectangle(); string text = ""; bool drawDay = false; bool enabled = true; Image bgImage = null; int i = -1; bool boldedDate = false; DateItem[] info; m_dayImage = null; dateAlign = GetStringAlignment(m_month.DateAlign); textAlign = GetStringAlignment(m_month.TextAlign); if ((m_month.SelectedMonth.Month == m_date.Month) || (m_month.Calendar.ShowTrailingDates)) { drawDay = true; } if (((m_date.DayOfWeek == DayOfWeek.Saturday) && (m_month.Colors.Weekend.Saturday)) || ((m_date.DayOfWeek == DayOfWeek.Sunday) && (m_month.Colors.Weekend.Sunday))) { bgColor1 = m_month.Colors.Weekend.BackColor1; bgColor2 = m_month.Colors.Weekend.BackColor2; dateColor = m_month.Colors.Weekend.Date; textColor = m_month.Colors.Weekend.Text; gradientMode = m_month.Colors.Weekend.GradientMode; } if (m_month.SelectedMonth.Month != m_date.Month) { bgColor1 = m_month.Colors.Trailing.BackColor1; bgColor2 = m_month.Colors.Trailing.BackColor2; gradientMode = m_month.Colors.Trailing.GradientMode; dateColor = m_month.Colors.Trailing.Date; textColor = m_month.Colors.Trailing.Text; } // Check if formatting should be applied if ((m_month.FormatTrailing) || (m_month.SelectedMonth.Month == m_date.Month)) { // check of there is formatting for this day if (queryInfo != null) { info = new DateItem[1]; info[0] = queryInfo; } else { info = m_calendar.GetDateInfo(this.Date); } if (info.Length > 0) { i = 0; } // go through the available dateitems while ((i < info.Length) && (drawDay)) { if (info.Length > 0) { DateItem dateInfo = info[i]; if (dateInfo.BackColor1 != Color.Empty) { bgColor1 = dateInfo.BackColor1; } if (dateInfo.BackColor2 != Color.Empty) { bgColor2 = dateInfo.BackColor2; } gradientMode = dateInfo.GradientMode; if (dateInfo.DateColor != Color.Empty) { dateColor = dateInfo.DateColor; } if (dateInfo.TextColor != Color.Empty) { textColor = dateInfo.TextColor; } text = dateInfo.Text; if (dateInfo.Weekend) { bgColor1 = m_month.Colors.Weekend.BackColor1; bgColor2 = m_month.Colors.Weekend.BackColor2; gradientMode = m_month.Colors.Weekend.GradientMode; dateColor = m_month.Colors.Weekend.Date; textColor = m_month.Colors.Weekend.Text; } boldedDate = dateInfo.BoldedDate; enabled = dateInfo.Enabled; if (!dateInfo.Enabled) { bgColor1 = m_month.Colors.Disabled.BackColor1; bgColor2 = m_month.Colors.Disabled.BackColor2; gradientMode = m_month.Colors.Disabled.GradientMode; dateColor = m_month.Colors.Disabled.Date; textColor = m_month.Colors.Disabled.Text; } m_dayImage = dateInfo.Image; if (m_dayImage != null) { m_imageRect = ImageRect(m_month.ImageAlign); } bgImage = dateInfo.BackgroundImage; } if (m_state == mcDayState.Selected) { dateColor = m_month.Colors.Selected.Date; textColor = m_month.Colors.Selected.Text; } if ((m_state == mcDayState.Focus) && (m_month.Calendar.ShowFocus)) { dateColor = m_month.Colors.Focus.Date; textColor = m_month.Colors.Focus.Text; } if (bgImage != null) { e.DrawImage(bgImage, m_rect); } else { if (gradientMode == mcGradientMode.None) { if (bgColor1 != Color.Transparent) { bgBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Background, bgColor1)); e.FillRectangle(bgBrush, m_rect); } } else { m_calendar.DrawGradient(e, Rectangle, bgColor1, bgColor2, gradientMode); } } ControlPaint.DrawBorder(e, m_rect, m_month.Colors.Days.Border, m_month.BorderStyles.Normal); if (m_dayImage != null) { if (enabled) { e.DrawImageUnscaled(m_dayImage, m_imageRect); } else { ControlPaint.DrawImageDisabled(e, m_dayImage, m_imageRect.X, m_imageRect.Y, m_month.Colors.Disabled.BackColor1); } } // Check if we should append month name to date if ((m_month.ShowMonthInDay) && ((m_date.AddDays(-1).Month != m_date.Month) || (m_date.AddDays(1).Month != m_date.Month))) { dateString = m_date.Day.ToString() + " " + m_calendar.m_dateTimeFormat.GetMonthName(m_date.Month); } else { dateString = m_date.Day.ToString(); } if (dateColor != Color.Transparent) { dateBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, dateColor)); CharacterRange[] characterRanges = { new CharacterRange(0, dateString.Length) }; dateAlign.SetMeasurableCharacterRanges(characterRanges); m_dateRgn = new Region[1]; // Should date be bolded ? if (!boldedDate) { e.DrawString(dateString, m_month.DateFont, dateBrush, m_rect, dateAlign); m_dateRgn = e.MeasureCharacterRanges(dateString, m_month.DateFont, m_rect, dateAlign); } else { e.DrawString(dateString, boldFont, dateBrush, m_rect, dateAlign); m_dateRgn = e.MeasureCharacterRanges(dateString, boldFont, m_rect, dateAlign); } } if ((text.Length > 0) && (textColor != Color.Transparent)) { textBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, textColor)); CharacterRange[] characterRanges = { new CharacterRange(0, text.Length) }; textAlign.SetMeasurableCharacterRanges(characterRanges); m_textRgn = new Region[1]; e.DrawString(text, m_month.TextFont, textBrush, m_rect, textAlign); m_textRgn = e.MeasureCharacterRanges(text, m_month.TextFont, m_rect, textAlign); } i++; } } dateBrush.Dispose(); bgBrush.Dispose(); textBrush.Dispose(); boldFont.Dispose(); dateAlign.Dispose(); textAlign.Dispose(); }
private void DrawButton(Graphics e, mcButtonState state, mcHeaderButtons button, Rectangle rect) { Bitmap image = null; int x = 0; int y = 0; int corr = 0; if (Application.RenderWithVisualStyles) { VisualStyleElement element = VisualStyleElement.Button.PushButton.Normal; if (m_calendar.Enabled) { if (state == mcButtonState.Hot) { element = VisualStyleElement.Button.PushButton.Hot; } else if (state == mcButtonState.Inactive) { element = VisualStyleElement.Button.PushButton.Disabled; } else if (state == mcButtonState.Pushed) { element = VisualStyleElement.Button.PushButton.Pressed; } } else { element = VisualStyleElement.Button.PushButton.Disabled; } VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(e, rect); switch (button) { case mcHeaderButtons.PreviousMonth: { image = m_prevMonthVs; x = rect.Left + 5; y = rect.Top + 5; break; } case mcHeaderButtons.PreviousYear: { image = m_prevYearVs; x = rect.Left + 4; y = rect.Top + 5; break; } case mcHeaderButtons.NextMonth: { image = m_nextMonthVs; x = rect.Right - 13; y = rect.Top + 5; break; } case mcHeaderButtons.NextYear: { image = m_nextYearVs; x = rect.Right - 16; y = rect.Top + 5; break; } } if ((m_calendar.Enabled) && (state != mcButtonState.Inactive)) { e.DrawImageUnscaled(image, new Point(x, y)); } else { ControlPaint.DrawImageDisabled(e, image, x, y, Color.Transparent); } } else { ButtonState btnState = ButtonState.Normal; if (m_calendar.Enabled) { if (state == mcButtonState.Hot) { btnState = ButtonState.Normal; } else if (state == mcButtonState.Inactive) { btnState = ButtonState.Inactive; } else if (state == mcButtonState.Pushed) { btnState = ButtonState.Pushed; } } else { btnState = ButtonState.Inactive; } switch (button) { case mcHeaderButtons.PreviousMonth: { ControlPaint.DrawScrollButton(e, rect, ScrollButton.Left, btnState); break; } case mcHeaderButtons.NextMonth: { ControlPaint.DrawScrollButton(e, rect, ScrollButton.Right, btnState); break; } case mcHeaderButtons.NextYear: { ControlPaint.DrawButton(e, rect, btnState); if (state == mcButtonState.Pushed) { corr = 1; } if ((m_calendar.Enabled) && (m_nextYearBtnState != mcButtonState.Inactive)) { e.DrawImage(m_nextYear, new Point(rect.Left + 3, rect.Top + 2 + corr)); } else { e.DrawImage(m_nextYearDisabled, new Point(rect.Left + 3, rect.Top + 2 + corr)); } break; } case mcHeaderButtons.PreviousYear: { ControlPaint.DrawButton(e, rect, btnState); if (state == mcButtonState.Pushed) { corr = 1; } if ((m_calendar.Enabled) && (m_prevYearBtnState != mcButtonState.Inactive)) { e.DrawImage(m_prevYear, new Point(rect.Left, rect.Top + 2 + corr)); } else { e.DrawImage(m_prevYearDisabled, new Point(rect.Left, rect.Top + 2 + corr)); } break; } } } }
protected override void OnPaint(PaintEventArgs e) { // Do we have an image list for use? if (_imageList != null) { // Is the button disabled? if (!this.Enabled) { // Do we have an image for showing when disabled? if (_imageIndexDisabled != -1) { // Any caller supplied attributes to modify drawing? if (null == _imageAttr) { // No, so use the simple DrawImage method e.Graphics.DrawImage(_imageList.Images[_imageIndexDisabled], new Point(1, 1)); } else { // Yes, need to use the more complex DrawImage method instead Image image = _imageList.Images[_imageIndexDisabled]; // Three points provided are upper-left, upper-right and // lower-left of the destination parallelogram. Point[] pts = new Point[3]; pts[0].X = 1; pts[0].Y = 1; pts[1].X = pts[0].X + image.Width; pts[1].Y = pts[0].Y; pts[2].X = pts[0].X; pts[2].Y = pts[1].Y + image.Height; e.Graphics.DrawImage(_imageList.Images[_imageIndexDisabled], pts, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel, _imageAttr); } } else { // No disbled image, how about an enabled image we can draw grayed? if (_imageIndexEnabled != -1) { // Yes, draw the enabled image but with color drained away ControlPaint.DrawImageDisabled(e.Graphics, _imageList.Images[_imageIndexEnabled], 1, 1, this.BackColor); } else { // No images at all. Do nothing. } } } else { // Button is enabled, any caller supplied attributes to modify drawing? if (null == _imageAttr) { // No, so use the simple DrawImage method e.Graphics.DrawImage(_imageList.Images[_imageIndexEnabled], (_mouseOver && _mouseCapture ? new Point(2, 2) : new Point(1, 1))); } else { // Yes, need to use the more complex DrawImage method instead Image image = _imageList.Images[_imageIndexEnabled]; // Three points provided are upper-left, upper-right and // lower-left of the destination parallelogram. Point[] pts = new Point[3]; pts[0].X = (_mouseOver && _mouseCapture) ? 2 : 1; pts[0].Y = (_mouseOver && _mouseCapture) ? 2 : 1; pts[1].X = pts[0].X + image.Width; pts[1].Y = pts[0].Y; pts[2].X = pts[0].X; pts[2].Y = pts[1].Y + image.Height; e.Graphics.DrawImage(_imageList.Images[_imageIndexEnabled], pts, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel, _imageAttr); } ButtonBorderStyle bs; // Decide on the type of border to draw around image if (_popupStyle) { if (_mouseOver && this.Enabled) { bs = (_mouseCapture ? ButtonBorderStyle.Inset : ButtonBorderStyle.Outset); } else { bs = ButtonBorderStyle.Solid; } } else { if (this.Enabled) { bs = ((_mouseOver && _mouseCapture) ? ButtonBorderStyle.Inset : ButtonBorderStyle.Outset); } else { bs = ButtonBorderStyle.Solid; } } ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, this.BackColor, _borderWidth, bs, this.BackColor, _borderWidth, bs, this.BackColor, _borderWidth, bs, this.BackColor, _borderWidth, bs); } } base.OnPaint(e); }
/// <summary> /// Raises the Paint event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> protected override void OnPaint(PaintCellEventArgs e) { base.OnPaint(e); // don't bother if the Cell is null if (e.Cell == null) { return; } // get the Cells value Color color = Color.Empty; if (e.Cell.Data != null && e.Cell.Data is Color) { color = (Color)e.Cell.Data; } Rectangle buttonRect = this.CalcDropDownButtonBounds(); Rectangle textRect = this.ClientRectangle; if (this.ShowDropDownButton) { textRect.Width -= buttonRect.Width - 1; } e.Graphics.SetClip(textRect); if (this.ShowColor) { Rectangle colorRect = this.CalcColorRect(e.Table.TableModel.Rows[e.Row].Alignment, e.Table.ColumnModel.Columns[e.Column].Alignment); if (color != Color.Empty) { using (SolidBrush brush = new SolidBrush(color)) { if (e.Enabled) { e.Graphics.FillRectangle(brush, colorRect); e.Graphics.DrawRectangle(SystemPens.ControlText, colorRect); } else { using (Bitmap b = new Bitmap(colorRect.Width, colorRect.Height)) { using (Graphics g = Graphics.FromImage(b)) { g.FillRectangle(brush, 0, 0, colorRect.Width, colorRect.Height); g.DrawRectangle(SystemPens.ControlText, 0, 0, colorRect.Width - 1, colorRect.Height - 1); } ControlPaint.DrawImageDisabled(e.Graphics, b, colorRect.X, colorRect.Y, this.BackColor); } } } textRect.X = colorRect.Right + 2; textRect.Width -= colorRect.Width + 4; } } if (this.ShowColorName) { string text = ""; if (color.IsEmpty) { text = "Empty"; } else if (color.IsNamedColor || color.IsSystemColor) { text = color.Name; } else { if (color.A != 255) { text += color.A + ", "; } text += color.R + ", " + color.G + ", " + color.B; } if (e.Enabled) { e.Graphics.DrawString(text, this.Font, this.ForeBrush, textRect, this.StringFormat); } else { e.Graphics.DrawString(text, this.Font, this.GrayTextBrush, textRect, this.StringFormat); } } if (e.Focused && e.Enabled) { Rectangle focusRect = this.ClientRectangle; if (this.ShowDropDownButton) { focusRect.Width -= buttonRect.Width; } ControlPaint.DrawFocusRectangle(e.Graphics, focusRect); } }
private int DrawImage(Graphics g, Rectangle r, Object imageSelector) { if (imageSelector == null || imageSelector == System.DBNull.Value) { return(0); } ImageList il = this.SmallImageList; //if (m_viewMode == ViewModes.Action || IsGroup(m_listItem)) // il = this.SmallImageList; //else // il = this.LargeImageList; if (il != null) { int imgIndex = -1; if (imageSelector is Int32) { imgIndex = (Int32)imageSelector; } else { String selectorAsString = imageSelector as String; if (selectorAsString != null) { imgIndex = il.Images.IndexOfKey(selectorAsString); } } if (imgIndex >= 0) { //Rectangle r2 = new Rectangle(r.X - this.Bounds.X, r.Y - this.Bounds.Y, r.Width, r.Height); Rectangle r2 = new Rectangle(r.X, r.Y, r.Width, r.Height); int flags = ILD_TRANSPARENT; if (m_listItem.Selected) { flags |= ILD_BLEND25; } MyGesture item = m_gestures[m_listItem.Index]; if ((item != null && item.AppGroup != null && !item.AppGroup.Checked) || !m_listItem.Checked) { ControlPaint.DrawImageDisabled(g, il.Images[imgIndex], r2.X, r2.Y, Color.Transparent); //Bitmap bmp = new Bitmap(il.ImageSize.Width, il.ImageSize.Height); //Graphics g2 = Graphics.FromImage(bmp); //ControlPaint.DrawImageDisabled(g2, il.Images[imgIndex], 0, 0, Color.Transparent); //g2.Dispose(); //ImageList il2 = new ImageList(); //il2.ImageSize = il.ImageSize; //il2.ColorDepth = il.ColorDepth; //il2.Images.Add(bmp); //ImageList_Draw(il2.Handle, 0, g.GetHdc(), r2.X, r2.Y, flags); //g.ReleaseHdc(); } else { ImageList_Draw(il.Handle, imgIndex, g.GetHdc(), r2.X, r2.Y, flags); g.ReleaseHdc(); } if (!m_gestures[m_listItem.Index].IsWorking) { ImageList_Draw(il.Handle, 0, g.GetHdc(), r2.X, r2.Y, flags); g.ReleaseHdc(); } return(il.ImageSize.Width); } } return(0); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); if (Parent is MainMenu) { if ((e.State & DrawItemState.HotLight) != 0) { e.Graphics.FillRectangle(SelectedBrush, e.Bounds); e.Graphics.DrawRectangle(SelectedBorderPen, e.Bounds.Left, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1); } else if ((e.State & DrawItemState.Selected) != 0) { e.Graphics.FillRectangle(SelectedBrush, e.Bounds); e.Graphics.DrawLine(new Pen(Color.Gray), e.Bounds.Left + 1, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Top); e.Graphics.DrawLine(new Pen(Color.Gray), e.Bounds.Left + 1, e.Bounds.Top, e.Bounds.Left + 1, e.Bounds.Bottom - 1); e.Graphics.DrawLine(new Pen(Color.DarkGray), e.Bounds.Right - 1, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Bottom - 1); } else { e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds); } e.Graphics.DrawString(Text, this.Font, ((e.State & DrawItemState.Inactive) != 0 ? Brushes.Gray : Brushes.Black), new PointF(e.Bounds.Left + 4, e.Bounds.Top + 4), Format); } // Draw Context Menu Items ------------------------------------------------------- else { // draw Item's selected state if ((e.State & DrawItemState.Selected) != 0) { if (this.Enabled) { e.Graphics.FillRectangle(SelectedBrush, e.Bounds); e.Graphics.DrawRectangle(SelectedBorderPen, e.Bounds.Left, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1); } } else { e.Graphics.FillRectangle(Brushes.White, e.Bounds); if (ShouldDisplayIconFrame) { e.Graphics.FillRectangle(GrayBrush, new Rectangle(e.Bounds.Left, e.Bounds.Top, 24, 24)); } } // draw item's image if (ShouldDisplayIconFrame && Picture != null) { if (this.Enabled) { if ((e.State & DrawItemState.Selected) != 0) { e.Graphics.DrawImage(GrayPicture, e.Bounds.Left + 5, e.Bounds.Top + 5); e.Graphics.DrawImage(Picture, e.Bounds.Left + 3, e.Bounds.Top + 3); } else { e.Graphics.DrawImage(Picture, e.Bounds.Left + 4, e.Bounds.Top + 4); } } else { ControlPaint.DrawImageDisabled(e.Graphics, Picture, e.Bounds.Left + 4, e.Bounds.Top + 4, Color.Transparent); } } // If not separator if (this.Text != "-") { Rectangle DisplayRect = new Rectangle(e.Bounds.Left + (ShouldDisplayIconFrame ? 24 : 0) + 6, e.Bounds.Top + 6, e.Bounds.Width - (ShouldDisplayIconFrame ? 24 : 0) - 18, e.Bounds.Bottom - 6); Format.Alignment = StringAlignment.Near; if (this.Enabled) { e.Graphics.DrawString(Text, this.Font, Brushes.Black, DisplayRect, Format); } else { e.Graphics.DrawString(Text, this.Font, Brushes.Gray, DisplayRect, Format); } if (Shortcut != Shortcut.None) { Format.Alignment = StringAlignment.Far; e.Graphics.DrawString(ShortcutString, this.Font, Brushes.Black, DisplayRect, Format); } } else { e.Graphics.DrawLine(Pens.Gray, e.Bounds.Left + (ShouldDisplayIconFrame ? 24 : 0) + 6, e.Bounds.Top + 1, e.Bounds.Right, e.Bounds.Top + 1); } } }
/// <summary> /// Raises the Paint event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> protected override void OnPaint(PaintCellEventArgs e) { base.OnPaint(e); // don't bother if the Cell is null if (e.Cell == null) { return; } // get the Cells value int intVal = 0; if (e.Cell.Data != null && e.Cell.Data is int) { intVal = (int)e.Cell.Data; } if (intVal < 0) { intVal = 0; } else if (intVal > 100) { intVal = 100; } // adjust the chunk rect so we don't draw over the // progress bars borders Rectangle chunkRect = this.ClientRectangle; chunkRect.Inflate(-2, -2); // if xp themes are enabled, shrink the size of the // progress bar as otherwise the focus rect appears // to go awol if the cell has focus if (ThemeManager.VisualStylesEnabled) { chunkRect.Inflate(-1, -1); } chunkRect.Width = (int)((((double)intVal) / 100d) * ((double)chunkRect.Width)); if (e.Enabled) { ThemeManager.DrawProgressBarChunks(e.Graphics, chunkRect); } else { using (Bitmap b = new Bitmap(chunkRect.Width, chunkRect.Height)) { using (Graphics g = Graphics.FromImage(b)) { ThemeManager.DrawProgressBarChunks(g, new Rectangle(0, 0, chunkRect.Width, chunkRect.Height)); } ControlPaint.DrawImageDisabled(e.Graphics, b, chunkRect.X, chunkRect.Y, this.BackBrush.Color); } } if (this.DrawPercentageText) { this.Alignment = ColumnAlignment.Center; this.LineAlignment = RowAlignment.Center; Font font = new Font(this.Font.FontFamily, this.Font.SizeInPoints, FontStyle.Bold); if (e.Enabled) { e.Graphics.DrawString("" + intVal + "%", font, SystemBrushes.ControlText, this.ClientRectangle, this.StringFormat); } else { e.Graphics.DrawString("" + intVal + "%", font, Brushes.White, this.ClientRectangle, this.StringFormat); } if (!ThemeManager.VisualStylesEnabled) { // remember the old clip area Region oldClip = e.Graphics.Clip; Rectangle clipRect = this.ClientRectangle; clipRect.Width = chunkRect.Width + 2; e.Graphics.SetClip(clipRect); if (e.Table.Enabled) { e.Graphics.DrawString("" + intVal + "%", font, SystemBrushes.HighlightText, this.ClientRectangle, this.StringFormat); } else { e.Graphics.DrawString("" + intVal + "%", font, Brushes.White, this.ClientRectangle, this.StringFormat); } // restore the old clip area e.Graphics.SetClip(oldClip, CombineMode.Replace); } } if (e.Focused && e.Enabled) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
protected override void OnPaint(PaintEventArgs e) { int imageHeight; int imageWidth; int paddingX; int paddingY; var dividerPen = new Pen(DividerColor, 0); Brush textBrush = new SolidBrush(TextColor); Brush disabledTextBrush = new SolidBrush(Color.Gray); Brush bgBrush = new SolidBrush(Color.Black); Color borderColor = Color.Black; var btnBorderStyle = ButtonBorderStyle.None; // Check if a ImageList exist ImageList list = GetImageList(); if (list != null) { // if so get Height and Width imageHeight = list.ImageSize.Height; imageWidth = list.ImageSize.Width; } else { // if not use default values imageHeight = 32; imageWidth = 32; } // Check if the item has belongs to a MozPane if (m_mozPane != null) { // If so get the padding paddingX = m_mozPane.Padding.Horizontal; paddingY = m_mozPane.Padding.Vertical; } else { // use some kind of padding if no daddy is found paddingX = 1; paddingY = 1; } var textRect = new Rectangle(); var imageRect = new Rectangle(0, 0, imageWidth, imageHeight); var borderRect = new Rectangle(); var f = new StringFormat(); var borderLocation = new Point(); borderLocation.X = 0; borderLocation.Y = 0; borderRect.Location = borderLocation; borderRect.Width = Width; borderRect.Height = Height; // Draw background e.Graphics.FillRectangle(new SolidBrush(BackgroundColor), DisplayRectangle); // Use Normal image for disabled state if (!Enabled) { m_state = MozItemState.Normal; } // A divider should not be able to be selected or recieve focus if (ItemStyle == MozItemStyle.Divider) { m_state = MozItemState.Normal; } // Check state for item, to decide image switch (m_state) { case MozItemState.Focus: { textBrush = new SolidBrush(FocusText); bgBrush = new SolidBrush(FocusColor); borderColor = FocusBorderColor; btnBorderStyle = FocusBorderStyle; if (m_imageCollection.FocusImage != null) { image = m_imageCollection.FocusImage; } else { // if focusimage isnt set use Normal image image = m_imageCollection.NormalImage; } break; } case MozItemState.Selected: { textBrush = new SolidBrush(SelectedText); bgBrush = new SolidBrush(SelectedColor); borderColor = SelectedBorderColor; btnBorderStyle = SelectedBorderStyle; if (m_imageCollection.SelectedImage != null) { image = m_imageCollection.SelectedImage; } else { image = m_imageCollection.NormalImage; } break; } case MozItemState.Normal: { image = m_imageCollection.NormalImage; bgBrush = new SolidBrush(BackgroundColor); btnBorderStyle = NormalBorderStyle; borderColor = BorderColor; break; } } e.Graphics.FillRectangle(bgBrush, borderRect); ControlPaint.DrawBorder(e.Graphics, borderRect, borderColor, btnBorderStyle); // check for itemStyle switch (m_itemStyle) { case MozItemStyle.Divider: { float ptY; float ptX; if (m_mozPane != null) { // Check MozPane orientation if (m_mozPane.Style == MozPaneStyle.Vertical) { ptY = borderRect.Top + (borderRect.Height / 2); e.Graphics.DrawLine(dividerPen, borderRect.Left, ptY, borderRect.Right, ptY); } else { ptX = borderRect.Left + (borderRect.Width / 2); e.Graphics.DrawLine(dividerPen, ptX, borderRect.Top, ptX, borderRect.Bottom); } } else { ptY = borderRect.Top + (borderRect.Height / 2); e.Graphics.DrawLine(dividerPen, borderRect.Left, ptY, borderRect.Right, ptY); } break; } case MozItemStyle.Text: { f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; textRect = borderRect; if (m_state == MozItemState.Selected) { textRect.X += 1; textRect.Y += 1; } if (Enabled) { e.Graphics.DrawString(Text, Font, textBrush, textRect, f); } else { e.Graphics.DrawString(Text, Font, disabledTextBrush, textRect, f); } break; } case MozItemStyle.Picture: { if (image != null) { // center image imageRect.X = ((borderRect.Width / 2) - (imageRect.Width / 2)); imageRect.Y = ((borderRect.Height / 2) - (imageRect.Height / 2)); if (m_state == MozItemState.Selected) { imageRect.X += 1; imageRect.Y += 1; } if (Enabled) { if (image != null) { e.Graphics.DrawImage(image, imageRect); } else if (image != null) { ControlPaint.DrawImageDisabled(e.Graphics, image, imageRect.X, imageRect.Y, BackgroundColor); } } } break; } case MozItemStyle.TextAndPicture: { f.LineAlignment = StringAlignment.Center; switch (m_textAlign) { case MozTextAlign.Bottom: { f.Alignment = StringAlignment.Center; textRect.Height = Font.Height + (2 * 4); textRect.Y = borderRect.Bottom - textRect.Height; textRect.X = borderRect.X; textRect.Width = borderRect.Width; imageRect.Y = borderRect.Top + 2; imageRect.X = ((borderRect.Width / 2) - imageRect.Width / 2); break; } case MozTextAlign.Top: { f.Alignment = StringAlignment.Center; textRect.Height = Font.Height + (2 * 4); textRect.Y = borderRect.Top; textRect.X = borderRect.X; textRect.Width = borderRect.Width; imageRect.Y = borderRect.Bottom - 2 - imageRect.Height; imageRect.X = ((borderRect.Width / 2) - imageRect.Width / 2); break; } case MozTextAlign.Right: { f.Alignment = StringAlignment.Near; textRect.Height = borderRect.Height - 2 * 4; textRect.Y = borderRect.Top + 4; textRect.X = borderRect.X + 4 + imageRect.Width + 4; textRect.Width = borderRect.Width - 4 - imageRect.Width; imageRect.X = 4; imageRect.Y = ((borderRect.Height / 2) - (imageRect.Height / 2)); break; } case MozTextAlign.Left: { f.Alignment = StringAlignment.Near; textRect.Height = borderRect.Height - 2 * 4; textRect.Y = borderRect.Top + 4; textRect.X = borderRect.X + 4; textRect.Width = borderRect.Width - 4 - imageRect.Width; imageRect.X = borderRect.Right - 4 - imageRect.Width; imageRect.Y = ((borderRect.Height / 2) - (imageRect.Height / 2)); break; } } // Check if enabled if (Enabled) { if (m_state == MozItemState.Selected) { imageRect.X += 1; imageRect.Y += 1; textRect.X += 1; textRect.Y += 1; } // draw image and text if (image != null) { e.Graphics.DrawImage(image, imageRect); } e.Graphics.DrawString(Text, Font, textBrush, textRect, f); } else { // Draw disabled image and text if (image != null) { ControlPaint.DrawImageDisabled(e.Graphics, image, imageRect.X, imageRect.Y, BackColor); } e.Graphics.DrawString(Text, Font, disabledTextBrush, textRect, f); } break; } } // tidy up dividerPen.Dispose(); textBrush.Dispose(); disabledTextBrush.Dispose(); bgBrush.Dispose(); }
// </snippet21> // <snippet22> // This method defines the behavior for rendering the // background of a ToolStripItem. If the item is a // RolloverItem, it paints the item's BackgroundImage // centered in the client area. If the mouse is in the // item's client area, a border is drawn around it. // If the item is on a drop-down or if it is on the // overflow, a gradient is painted in the background. protected override void OnRenderItemBackground( ToolStripItemRenderEventArgs e) { base.OnRenderItemBackground(e); RolloverItem item = e.Item as RolloverItem; // If the ToolSTripItem is of type RolloverItem, // perform custom rendering for the background. if (item != null) { if (item.Placement == ToolStripItemPlacement.Overflow || item.IsOnDropDown) { using (LinearGradientBrush b = new LinearGradientBrush( item.ContentRectangle, Color.Salmon, Color.DarkRed, 0f, false)) { e.Graphics.FillRectangle(b, item.ContentRectangle); } } // The RolloverItem control only supports // the ImageLayout.Center setting for the // BackgroundImage property. if (item.BackgroundImageLayout == ImageLayout.Center) { // Get references to the item's ContentRectangle // and BackgroundImage, for convenience. Rectangle cr = item.ContentRectangle; Image bgi = item.BackgroundImage; // Compute the center of the item's ContentRectangle. int centerX = (cr.Width - bgi.Width) / 2; int centerY = (cr.Height - bgi.Height) / 2; // If the item is selected, draw the background // image as usual. Otherwise, draw it as disabled. if (item.Selected) { e.Graphics.DrawImage(bgi, centerX, centerY); } else { ControlPaint.DrawImageDisabled( e.Graphics, bgi, centerX, centerY, item.BackColor); } } // If the item is in the rollover state, // draw a border around it. if (item.Rollover) { ControlPaint.DrawFocusRectangle( e.Graphics, item.ContentRectangle); } } }
public override void Render(Graphics g, Rectangle r) { DrawBackground(g, r); r = ApplyCellPadding(r); // Convert our aspect to a numeric value var aspect = (RatingEntry)Aspect; if (aspect.Equals(RatingEntry.NotAvailable)) { DrawText(g, r, Localisable.NotAvailable); } else if (aspect.AverageRating.HasValue || aspect.MyRating.HasValue) { var aspectValue = (float)(aspect.MyRating ?? aspect.AverageRating); // Calculate how many images we need to draw to represent our aspect value int numberOfImages; if (aspectValue <= _minimumValue) { numberOfImages = 1; } else if (aspectValue <= (_maximumValue + _minimumValue) / 2) { numberOfImages = 2; } else if (aspectValue < _maximumValue) { numberOfImages = 3; } else { numberOfImages = _maxNumberImages; } // If we need to shrink the image, what will its on-screen dimensions be? var imageScaledWidth = _baseImage.Width; var imageScaledHeight = _baseImage.Height; if (r.Height < _baseImage.Height) { imageScaledWidth = (int)(_baseImage.Width * (float)r.Height / _baseImage.Height); imageScaledHeight = r.Height; } // Calculate where the images should be drawn var imageBounds = r; imageBounds.Width = _maxNumberImages * (imageScaledWidth + Spacing) - Spacing; imageBounds.Height = imageScaledHeight; imageBounds = AlignRectangle(r, imageBounds); // Finally, draw the images var singleImageRect = new Rectangle(imageBounds.X, imageBounds.Y, imageScaledWidth, imageScaledHeight); var backgroundColor = GetBackgroundColor(); for (var i = 0; i < numberOfImages; i++) { if (ListItem.Enabled) { var displayedImage = aspect.MyRating.HasValue || Settings.Default.MiscColorblind ? _baseImage : _coloredImages[numberOfImages - 1]; g.DrawImage(displayedImage, singleImageRect); //DrawImage(g, singleImageRect, image); } else { ControlPaint.DrawImageDisabled(g, _baseImage, singleImageRect.X, singleImageRect.Y, backgroundColor); } singleImageRect.X += (imageScaledWidth + Spacing); } } else { DrawText(g, r, CommonStrings.Unknown); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { /* * Graphics initialization. */ Graphics g = e.Graphics; /* * Container bounds. */ Rectangle tweakedRect = new Rectangle( this.ClientRectangle.X + 1, this.ClientRectangle.Y + 1, this.ClientRectangle.Width - 2, this.ClientRectangle.Height - 2 ); Rectangle borderRect = new Rectangle( this.ClientRectangle.X + 1, this.ClientRectangle.Y + 1, this.ClientRectangle.Width - 2, this.ClientRectangle.Height - 2 ); /* * Background */ if (this.Pushed && !this.IsMouseOver) { using (SolidBrush sb = new SolidBrush(SystemColors.ControlDark)) { g.FillRectangle(sb, tweakedRect); } } else if (this.IsPressed) { using (SolidBrush sb = new SolidBrush(SystemColors.ControlDark)) { g.FillRectangle(sb, tweakedRect); } } else { using (SolidBrush sb = new SolidBrush(SystemColors.Control)) { g.FillRectangle(sb, tweakedRect); } } /* * Image */ Image image = null; /* Try to work via Image property. */ if (this.Image != null) { image = this.Image; } /* Try to work via ImageList property. */ else if (this.ImageList != null && this.ImageIndex >= 0 && this.ImageIndex < this.ImageList.Images.Count) { image = this.ImageList.Images[this.ImageIndex]; } Rectangle imageRect = Rectangle.Empty; /* The image is found and we will draw it. */ if (image != null) { int xOffset = 4; int yOffset = tweakedRect.Height / 2 - image.Size.Height / 2 + 1; imageRect = new Rectangle( new Point(xOffset, yOffset), image.Size ); if (this.IsPressed || this.Pushed) { imageRect.Offset(1, 1); } /* The button is enabled. */ if (this.Enabled) { g.DrawImage(image, imageRect); } /* The button is disabled. */ else { ControlPaint.DrawImageDisabled( g, image, imageRect.X, imageRect.Y, Color.Transparent ); } } /* * Text */ if (this.Text != null && this.Text != "") { Rectangle textRect = Rectangle.Empty; if (imageRect.IsEmpty) { textRect = new Rectangle( tweakedRect.X + 4, tweakedRect.Y + 4, tweakedRect.Width - 8, tweakedRect.Height - 8 ); } else { textRect = new Rectangle( imageRect.Right + 4, tweakedRect.Y + 4, tweakedRect.Width - imageRect.Width - 8, tweakedRect.Height - 8 ); } if (this.IsPressed || this.Pushed) { textRect.Offset(0, 1); } StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; if (this.WordWrap == false) { sf.FormatFlags = StringFormatFlags.NoWrap; } string bufferString = ""; if (this.WordWrap == false && this.EatLine == true) { Debug.Assert(this.StringProcessor != null, "this.StringProcessor != null."); bufferString = this.StringProcessor.EatLine(this.Text, this.Font, textRect.Width, g); } else { bufferString = this.Text; } if (this.Enabled) { using (SolidBrush sb = new SolidBrush(this.ForeColor)) { g.DrawString(bufferString, this.Font, sb, textRect, sf); } } else { using (SolidBrush sb = new SolidBrush(SystemColors.GrayText)) { g.DrawString(bufferString, this.Font, sb, textRect, sf); } } } /* * Border */ /* The button is pressed or pushed down. */ if (this.IsPressed || this.Pushed) { /* Left and top borders are dark. */ using (Pen pen = new Pen(SystemColors.ControlDark)) { g.DrawLine( pen, NuGenControlPaint.RectBLCorner(borderRect), NuGenControlPaint.RectTLCorner(borderRect) ); g.DrawLine( pen, NuGenControlPaint.RectTLCorner(borderRect), NuGenControlPaint.RectTRCorner(borderRect) ); } /* Right and bottom borders are light. */ using (Pen pen = new Pen(SystemColors.ControlLight)) { g.DrawLine( pen, NuGenControlPaint.RectTRCorner(borderRect), NuGenControlPaint.RectBRCorner(borderRect) ); g.DrawLine( pen, NuGenControlPaint.RectBLCorner(borderRect), NuGenControlPaint.RectBRCorner(borderRect) ); } } /* The button is not pushed or pressed and the mouse is over the button. */ else if (this.IsMouseOver && !this.IsPressed) { /* Left and top borders are light. */ using (Pen pen = new Pen(SystemColors.ControlLight)) { g.DrawLine( pen, NuGenControlPaint.RectBLCorner(borderRect), NuGenControlPaint.RectTLCorner(borderRect) ); g.DrawLine( pen, NuGenControlPaint.RectTLCorner(borderRect), NuGenControlPaint.RectTRCorner(borderRect) ); } /* Right and bottom borders are dark. */ using (Pen pen = new Pen(SystemColors.ControlDark)) { g.DrawLine( pen, NuGenControlPaint.RectTRCorner(borderRect), NuGenControlPaint.RectBRCorner(borderRect) ); g.DrawLine( pen, NuGenControlPaint.RectBLCorner(borderRect), NuGenControlPaint.RectBRCorner(borderRect) ); } } /* The button is in its defalt state. */ else { /* We don't need borders in the default state. */ using (Pen pen = new Pen(SystemColors.Control)) { g.DrawRectangle(pen, borderRect); } } }
/// <summary> /// Primary function for painting the button. This method should be overridden instead of OnPaint. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="bounds">The bounds.</param> protected virtual void PaintButton(Graphics graphics, Rectangle bounds) { System.Diagnostics.Debug.WriteLine($"PaintButton: desMode:{this.IsDesignMode()};vsEnabled:{Application.RenderWithVisualStyles};vsOnOS:{VisualStyleInformation.IsSupportedByOS};btnState:{ButtonState};enabled:{Enabled};imgCt:{(ImageList != null ? ImageList.Images.Count : 0)}"); if (InitializeRenderer()) { if (OnGlass) { rnd.DrawGlassBackground(graphics, bounds, bounds); } else { rnd.DrawParentBackground(graphics, bounds, this); rnd.DrawBackground(graphics, bounds); } } else { if (ImageList != null && ImageList.Images.Count > 0) { int idx = (int)ButtonState - 1; if (ImageList.Images.Count == 1) { idx = 0; } else if (ImageList.Images.Count == 2) { idx = ButtonState == PushButtonState.Disabled ? 1 : 0; } else if (ImageList.Images.Count == 3) { idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1; } bool forceDisabled = !Enabled && ImageList.Images.Count == 1; if (OnGlass) { VisualStyleRendererExtension.DrawGlassImage(null, graphics, bounds, ImageList.Images[idx], forceDisabled); } else { if (!Application.RenderWithVisualStyles && VisualStyleInformation.IsSupportedByOS) { System.Drawing.Drawing2D.GraphicsContainer g = graphics.BeginContainer(); Rectangle translateRect = bounds; graphics.TranslateTransform(-bounds.Left, -bounds.Top); PaintEventArgs pe = new PaintEventArgs(graphics, translateRect); InvokePaintBackground(Parent, pe); InvokePaint(Parent, pe); graphics.ResetTransform(); graphics.EndContainer(g); } else { graphics.Clear(Parent.BackColor); } if (forceDisabled) { ControlPaint.DrawImageDisabled(graphics, ImageList.Images[idx], 0, 0, Color.Transparent); } else { //base.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx); //VisualStyleRendererExtender.DrawGlassImage(null, graphics, bounds, base.ImageList.Images[idx], forceDisabled); // Not 7 graphics.DrawImage(ImageList.Images[idx], bounds, bounds, GraphicsUnit.Pixel); // Works on XP, not 7, with Parent.BackColor } } } /*else if (this.ImageList != null && this.ImageList.Images.Count > 1) * { * int idx = (int)ButtonState - 1; * if (this.ImageList.Images.Count == 2) * idx = ButtonState == PushButtonState.Disabled ? 1 : 0; * if (this.ImageList.Images.Count == 3) * idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1; * if (rnd != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled()) * rnd.DrawGlassIcon(graphics, bounds, this.ImageList, idx); * else * this.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx); * }*/ // No image so draw standard button else { ButtonRenderer.DrawParentBackground(graphics, bounds, this); ButtonRenderer.DrawButton(graphics, bounds, ButtonState); } } if (Focused) { ControlPaint.DrawFocusRectangle(graphics, bounds); } }