protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BidiGraphics g = new BidiGraphics(e.Graphics, _controlRect); //draw the splitter line GraphicsHelper.TileFillScaledImageHorizontally(g, extendedEntrySeparatorTileImage, _lineRect); //draw the More... box Color backgroundColor = Color.FromArgb(128, 128, 128); SizeF moreTextSize = g.MeasureText(_moreText, font); int morePadding = 0; int moreRightOffset = 1; Size moreRectSize = new Size(Convert.ToInt32(moreTextSize.Width) + morePadding * 2, Convert.ToInt32(moreTextSize.Height) + morePadding * 2); Point moreRectLocation = new Point(_controlRect.Right - moreRectSize.Width - moreRightOffset, _lineRect.Bottom); Rectangle moreRect = new Rectangle(moreRectLocation, moreRectSize); // It's necessary to double-buffer the text drawing, because GDI // text drawing doesn't work well in these behavior controls. using (Bitmap bitmap = new Bitmap(moreRect.Width, moreRect.Height)) { using (Graphics moreG = Graphics.FromImage(bitmap)) { using (SolidBrush b = new SolidBrush(backgroundColor)) moreG.FillRectangle(b, 0, 0, moreRect.Width, moreRect.Height); new BidiGraphics(moreG, moreRect.Size).DrawText(_moreText, font, new Rectangle(Point.Empty, moreRect.Size), Color.White, backgroundColor, TextFormatFlags.Default); } g.DrawImage(false, bitmap, moreRect); } }
/// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle); // Paint. g.DrawText(Text, Font, ClientRectangle, Color.FromArgb(GraphicsHelper.Opacity(Enabled ? 100.0 : 50.0), ForeColor), stringFormat); Size size = new Size(ClientSize.Width, ClientSize.Height); measuredTextSize = g.MeasureText(Text, Font, size, stringFormat); }
protected override void OnPaint(PaintEventArgs e) { BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle); using (Brush b = new SolidBrush(ColorizedResources.Instance.BorderDarkColor)) g.FillRectangle(b, ClientRectangle); TextFormatFlags tf = TextFormatFlags.VerticalCenter; int width = g.MeasureText(Text, Font).Width; g.DrawText(Text, Font, new Rectangle(20, -1, width, ClientSize.Height), _uiTheme.TextColor, tf); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); BidiGraphics g = new BidiGraphics(e.Graphics, summaryTextRect); //paint the background over the last text paint using (Brush backBrush = new SolidBrush(BackColor)) { g.FillRectangle(backBrush, summaryTextRect); } Color textColor = Color.DarkGray; Size sizeTextSize; if (linkToSizeText != null) { sizeTextSize = g.MeasureText(linkToSizeText, Font, summaryTextRect.Size, imageFileSizeFormat); } else { sizeTextSize = Size.Empty; } Size summaryTextSize = g.MeasureText(linkToSummaryText, Font, new Size(summaryTextRect.Size.Width - sizeTextSize.Width - ScaleX(summarySizeSpacing), sizeTextSize.Height), imageFileSummaryFormat); Rectangle summaryTextLayoutRect = new Rectangle(new Point(summaryTextRect.X, summaryTextRect.Y), summaryTextSize); Rectangle sizeTextLayoutRect = new Rectangle(new Point(summaryTextLayoutRect.Right + summarySizeSpacing, summaryTextRect.Y), sizeTextSize); Rectangle imageViewerTextLayoutRect = new Rectangle(summaryTextRect.X, sizeTextLayoutRect.Bottom + ScaleY(3), ClientRectangle.Width, (int)Math.Ceiling(Font.GetHeight(e.Graphics))); g.DrawText(linkToSummaryText, this.Font, summaryTextLayoutRect, textColor, imageFileSummaryFormat); g.DrawText(linkToSizeText, this.Font, sizeTextLayoutRect, textColor, imageFileSummaryFormat); if (linkToImageViewer != "") { g.DrawText(linkToImageViewer, this.Font, imageViewerTextLayoutRect, textColor, imageFileSummaryFormat); } }
public static void DrawErrorMockPlayer(Bitmap img, BidiGraphics bidiGraphics, string message) { int LEFT_PADDING = 30; int RIGHT_PADDING = 10; int ERROR_IMAGE_WIDTH = 32; int ERROR_IMAGE_HEIGHT = 32; int IMAGE_TO_TEXT_PADDING = 7; int PLACEHOLDER_HEIGHT = img.Height; int PLACEHOLDER_WIDTH = img.Width; int VERTICAL_OFFSET = 30; int LINE_BREAK_PADDING = 4; Size titleSize = bidiGraphics.MeasureText(Res.Get(StringId.VideoError), Res.GetFont(FontSize.XXLarge, FontStyle.Bold), new Size(PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING, PLACEHOLDER_HEIGHT - VERTICAL_OFFSET), TextFormatFlags.WordBreak); bidiGraphics.DrawText(Res.Get(StringId.VideoError), Res.GetFont(FontSize.XXLarge, FontStyle.Bold), new Rectangle(LEFT_PADDING + ERROR_IMAGE_WIDTH + IMAGE_TO_TEXT_PADDING, VERTICAL_OFFSET + (ERROR_IMAGE_HEIGHT / 2) - (titleSize.Height / 2), PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING, PLACEHOLDER_HEIGHT - VERTICAL_OFFSET), Color.White, TextFormatFlags.WordBreak); bidiGraphics.DrawText(message, Res.GetFont(FontSize.XLarge, FontStyle.Regular), new Rectangle(LEFT_PADDING + ERROR_IMAGE_WIDTH + IMAGE_TO_TEXT_PADDING, VERTICAL_OFFSET + (ERROR_IMAGE_HEIGHT / 2) - (titleSize.Height / 2) + titleSize.Height + LINE_BREAK_PADDING, PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING, PLACEHOLDER_HEIGHT - (VERTICAL_OFFSET + titleSize.Height + LINE_BREAK_PADDING)), Color.White, TextFormatFlags.WordBreak); bidiGraphics.DrawImage(false, ResourceHelper.LoadAssemblyResourceBitmap("Video.Images.Error.gif"), LEFT_PADDING, VERTICAL_OFFSET); }
protected override void OnPaint(PaintEventArgs e) { BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle); // draw image const int HEADER_X_INSET = 0; const int HEADER_Y_INSET = 0; g.DrawImage(false, _headerImage, HEADER_X_INSET, HEADER_Y_INSET); // draw text centered vertically const int TEXT_X_INSET = 5; Size textSize = g.MeasureText(_label, Font); int textY = (Height / 2) - (textSize.Height / 2); Color textColor = !SystemInformation.HighContrast ? Color.FromArgb(0, 77, 131) : SystemColors.WindowText; Rectangle textRect = new Rectangle(new Point(HEADER_X_INSET + _headerImage.Width + TEXT_X_INSET, textY), textSize); g.DrawText(_label, Font, textRect, textColor); }
private Bitmap CreateBitmap() { Bitmap bitmap = new Bitmap(_backgroundImage.Width, _backgroundImage.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(bitmap)) { BidiGraphics g = new BidiGraphics(graphics, bitmap.Size); // draw transparent background image g.DrawImage(false, _backgroundImage, new Rectangle(0, 0, _backgroundImage.Width, _backgroundImage.Height)); // draw logo image g.DrawImage(false, _logoImage, new Rectangle( (ClientSize.Width - _logoImage.Width) / 2, 120 - _logoImage.Height, _logoImage.Width, _logoImage.Height)); // draw copyright notice string splashText = Res.Get(StringId.SplashScreenCopyrightNotice); using (Font font = new Font(Font.FontFamily, 7.5f)) { const int TEXT_PADDING_H = 36; const int TEXT_PADDING_V = 26; int textWidth = Size.Width - 2 * TEXT_PADDING_H; int textHeight = Convert.ToInt32( g.MeasureText(splashText, font, new Size(textWidth, 0), TextFormatFlags.WordBreak).Height, CultureInfo.InvariantCulture); // GDI text can't be drawn on an alpha-blended surface. So we render a black-on-white // bitmap, then use a ColorMatrix to effectively turn it into an alpha mask. using (Bitmap textBitmap = new Bitmap(textWidth, textHeight, PixelFormat.Format32bppRgb)) { using (Graphics tbG = Graphics.FromImage(textBitmap)) { tbG.FillRectangle(Brushes.Black, 0, 0, textWidth, textHeight); new BidiGraphics(tbG, textBitmap.Size). DrawText(splashText, font, new Rectangle(0, 0, textWidth, textHeight), Color.White, Color.Black, TextFormatFlags.WordBreak); } Rectangle textRect = new Rectangle(TEXT_PADDING_H, ClientSize.Height - TEXT_PADDING_V - textHeight, textWidth, textHeight); using (ImageAttributes ia = new ImageAttributes()) { ColorMatrix cm = new ColorMatrix(new float[][] { new float[] { 0, 0, 0, 1f / 3f, 0 }, new float[] { 0, 0, 0, 1f / 3f, 0 }, new float[] { 0, 0, 0, 1f / 3f, 0 }, new float[] { 0, 0, 0, 0, 0 }, new float[] { 0.9372f, 0.9372f, 0.9372f, 0, 0 }, }); ia.SetColorMatrix(cm); g.DrawImage(false, textBitmap, textRect, 0, 0, textWidth, textHeight, GraphicsUnit.Pixel, ia); } } } } return(bitmap); }
protected override void OnDrawItem(DrawItemEventArgs e) { // screen invalid drawing states if (DesignMode || e.Index == -1) { return; } // get post-source we are rendering IPostEditorPostSource postSource = (Items[e.Index] as PostSourceItem).PostSource; // determine image and text to use Image postSourceImage; if (e.Index == _draftsIndex) { postSourceImage = _showLargeIcons ? _draftsImageLarge : _draftsImage; } else if (e.Index == _recentPostsIndex) { postSourceImage = _showLargeIcons ? _recentPostsImageLarge : _recentPostsImage; } else { postSourceImage = _showLargeIcons ? _weblogImageLarge : _weblogImage; } // determine state bool selected = (e.State & DrawItemState.Selected) > 0; // calculate colors Color backColor, textColor; if (selected) { if (Focused) { backColor = _theme.backColorSelectedFocused; textColor = _theme.textColorSelectedFocused; } else { backColor = _theme.backColorSelected; textColor = _theme.textColorSelected; } } else { backColor = _theme.backColor; textColor = _theme.textColor; } BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds); // draw background using (SolidBrush solidBrush = new SolidBrush(backColor)) g.FillRectangle(solidBrush, e.Bounds); if (_showLargeIcons) { // center the image within the list box int imageLeft = e.Bounds.Left + ((e.Bounds.Width / 2) - (ScaleX(postSourceImage.Width) / 2)); int imageTop = e.Bounds.Top + ScaleY(LARGE_TOP_INSET); g.DrawImage(false, postSourceImage, new Rectangle(imageLeft, imageTop, ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height))); // setup string format TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.HorizontalCenter; // calculate standard text drawing metrics int leftMargin = ScaleX(ELEMENT_PADDING); int topMargin = imageTop + ScaleY(postSourceImage.Height) + ScaleY(ELEMENT_PADDING); int fontHeight = g.MeasureText(postSource.Name, e.Font).Height; // caption // calculate layout rectangle Rectangle layoutRectangle = new Rectangle( leftMargin, topMargin, e.Bounds.Width - (2 * ScaleX(ELEMENT_PADDING)), fontHeight * TITLE_LINES); // draw caption g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat); } else { // draw post icon g.DrawImage(false, postSourceImage, new Rectangle(e.Bounds.Left + ScaleX(ELEMENT_PADDING), e.Bounds.Top + ScaleY(SMALL_TOP_INSET), ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height))); // setup string format TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis; // calculate standard text drawing metrics int leftMargin = ScaleX(ELEMENT_PADDING) + ScaleX(postSourceImage.Width) + ScaleX(ELEMENT_PADDING); int topMargin = e.Bounds.Top + ScaleY(SMALL_TOP_INSET); int fontHeight = g.MeasureText(postSource.Name, e.Font).Height; // caption // calculate layout rectangle Rectangle layoutRectangle = new Rectangle( leftMargin, topMargin, e.Bounds.Width - leftMargin - ScaleX(ELEMENT_PADDING), fontHeight * TITLE_LINES); // draw caption g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat); } // draw focus rectange if necessary e.DrawFocusRectangle(); }
protected override void OnDrawItem(DrawItemEventArgs e) { // screen invalid drawing states if (DesignMode || e.Index == -1) { return; } // get post we are rendering PostInfo postInfo = (Items[e.Index] as PostInfoItem).PostInfo; // determine state bool selected = (e.State & DrawItemState.Selected) > 0; // calculate colors Color backColor, textColor; if (selected) { if (Focused) { backColor = _theme.backColorSelectedFocused; textColor = _theme.textColorSelectedFocused; } else { backColor = _theme.backColorSelected; textColor = _theme.textColorSelected; } } else { backColor = _theme.backColor; textColor = _theme.textColor; } BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds); // setup standard string format TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.NoPrefix; // draw background using (SolidBrush solidBrush = new SolidBrush(backColor)) g.FillRectangle(solidBrush, e.Bounds); // draw top-line if necessary //if ( !selected ) { using (Pen pen = new Pen(_theme.topLineColor)) g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - ScaleY(1)); } // draw post icon g.DrawImage(false, _blogPostImage, new Rectangle( e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(TITLE_INSET), ScaleX(_blogPostImage.Width), ScaleY(_blogPostImage.Height))); // calculate standard text drawing metrics int leftMargin = ScaleX(HORIZONTAL_INSET) + ScaleX(_blogPostImage.Width) + ScaleX(HORIZONTAL_INSET); int topMargin = e.Bounds.Top + ScaleY(TITLE_INSET); // draw title line // post date string dateText = postInfo.PrettyDateDisplay; Size dateSize = g.MeasureText(dateText, e.Font); Rectangle dateRectangle = new Rectangle( e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - dateSize.Width, topMargin, dateSize.Width, dateSize.Height); g.DrawText(dateText, e.Font, dateRectangle, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix); // post title int titleWidth = dateRectangle.Left - leftMargin - ScaleX(DATE_PADDING); string titleString = String.Format(CultureInfo.CurrentCulture, "{0}", postInfo.Title); int fontHeight = g.MeasureText(titleString, e.Font).Height; Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight); g.DrawText( titleString, e.Font, titleRectangle, textColor, ellipsesStringFormat); // draw post preview // calculate layout rectangle Rectangle layoutRectangle = new Rectangle( leftMargin, topMargin + fontHeight + ScaleY(PREVIEW_INSET), e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET), fontHeight * PREVIEW_LINES); // draw post preview string postPreview = postInfo.PlainTextContents; if (PostSource.HasMultipleWeblogs && (postInfo.BlogName != String.Empty)) { postPreview = String.Format(CultureInfo.CurrentCulture, "{0} - {1}", postInfo.BlogName, postPreview); } g.DrawText( postPreview, e.Font, layoutRectangle, textColor, ellipsesStringFormat); // focus rectange if necessary e.DrawFocusRectangle(); }
protected override void OnDrawItem(DrawItemEventArgs e) { // screen invalid drawing states if (DesignMode || e.Index == -1) { return; } // get video we are rendering IVideo video = Items[e.Index] as IVideo; // determine state bool selected = ((e.State & DrawItemState.Selected) > 0) && !_preventSelectionPainting; // calculate colors Color textColor; if (selected) { if (Focused) { textColor = SystemColors.HighlightText; } else { textColor = SystemColors.ControlText; } } else { textColor = SystemColors.ControlText; } Color previewColor = Color.FromArgb(200, textColor); BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds); // setup standard string format TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis; // draw background e.DrawBackground(); //using (SolidBrush solidBrush = new SolidBrush(backColor)) // g.FillRectangle(solidBrush, e.Bounds); // draw the thumbnail image Rectangle thumbnailRect = new Rectangle(e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(VERTICAL_INSET), THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT); VideoThumbnail thumbnail = _thumbnailManager.GetThumbnail(video); thumbnail.Draw(g, e.Font, thumbnailRect); // calculate standard text drawing metrics int leftMargin = ScaleX(HORIZONTAL_INSET) + THUMBNAIL_IMAGE_WIDTH + ScaleX(HORIZONTAL_INSET); int topMargin = e.Bounds.Top + ScaleY(VERTICAL_INSET); int fontHeight = g.MeasureText(video.Title, e.Font).Height; // draw title and duration int titleWidth; Rectangle durationRectangle; using (Font hyperlinkFont = new Font(e.Font, FontStyle.Underline)) { titleWidth = e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - leftMargin; Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight); string title = video.Title ?? ""; g.DrawText(title, hyperlinkFont, titleRectangle, selected ? textColor : SystemColors.HotTrack, ellipsesStringFormat); } using (Font durationFont = new Font(e.Font, FontStyle.Regular)) // was bold { durationRectangle = new Rectangle(leftMargin, topMargin + fontHeight + 3, titleWidth, fontHeight); string duration = String.Format(CultureInfo.InvariantCulture, "{0:00}:{1:00}", video.LengthSeconds / 60, video.LengthSeconds % 60); g.DrawText( duration, durationFont, durationRectangle, textColor, ellipsesStringFormat); } // draw description // calculate layout rectangle Rectangle layoutRectangle = new Rectangle( leftMargin, durationRectangle.Bottom + ScaleY(VERTICAL_INSET), e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET), e.Bounds.Bottom - ScaleY(VERTICAL_INSET) - durationRectangle.Bottom - ScaleY(VERTICAL_INSET)); // draw description g.DrawText( video.Description, e.Font, layoutRectangle, previewColor, ellipsesStringFormat); // draw bottom-line if necessary if (!selected) { using (Pen pen = new Pen(SystemColors.ControlLight)) g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - ScaleY(1), e.Bounds.Right, e.Bounds.Bottom - ScaleY(1)); } // focus rectange if necessary e.DrawFocusRectangle(); }