/// <summary> /// Wrapper around BitBlt. /// </summary> /// <param name="dest"></param> /// <param name="destClip">Clipping rectangle on dest</param> /// <param name="graphics"></param> /// <param name="bltFrom">Upper-left point on src to blt from</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">dest or graphics</exception> public static void CopyGraphics(Graphics dest, Rectangle destClip, Graphics graphics, Point bltFrom) { dest.ThrowIfNull(nameof(dest)); graphics.ThrowIfNull(nameof(graphics)); BitBlt(dest.GetHdc(), destClip.Left, destClip.Top, destClip.Width, destClip.Height, graphics.GetHdc(), bltFrom.X, bltFrom.Y, SRCCOPY); }
/// <summary> /// Draws strings by individual slices. Position of the text is /// calculated by overridable <c>GetTextPosition</c> method of the /// <c>PieSlice</c> type. /// </summary> /// <param name="graphics"><c>Graphics</c> object.</param> /// <exception cref="System.ArgumentNullException">graphics</exception> public void PlaceTexts(Graphics graphics) { Debug.Assert(m_font != null); Debug.Assert(m_foreColor != Color.Empty); graphics.ThrowIfNull(nameof(graphics)); using (StringFormat drawFormat = new StringFormat()) { drawFormat.Alignment = StringAlignment.Center; drawFormat.LineAlignment = StringAlignment.Center; using (Brush fontBrush = new SolidBrush(m_foreColor)) { int num = 0; PointF[] points = new PointF[m_pieSlices.Length]; foreach (PieSlice slice in m_pieSlices) { if (!String.IsNullOrEmpty(slice.Text)) { PointF point = slice.GetTextPosition; foreach (PointF oldpoint in points) { for (int x = 0; x <= 1; x++) { float diffy = oldpoint.Y - point.Y; float diffx = oldpoint.X - point.X; if (diffy < 0) diffy *= -1; if (diffx < 0) diffx *= -1; if (diffx < 70 && diffy < 16) point = slice.GetTextPositionOut(x == 0 ? 4.5f : 2.2f); } } points[num] = point; graphics.DrawString(slice.Text, m_font, fontBrush, point, drawFormat); } num++; } } } }
/// <summary> /// Draws the <c>Quadrilateral</c> with <c>Graphics</c> provided. /// </summary> /// <param name="graphics"><c>Graphics</c> used to draw.</param> /// <param name="pen"><c>Pen</c> used to draw outline.</param> /// <param name="brush"><c>Brush</c> used to fill the inside.</param> /// <exception cref="System.ArgumentNullException">graphics</exception> public void Draw(Graphics graphics, Pen pen, Brush brush) { graphics.ThrowIfNull(nameof(graphics)); graphics.FillPath(brush, m_path); graphics.DrawPath(pen, m_path); }
/// <summary> /// Sets the text character spacing. /// </summary> /// <param name="graphics">The g.</param> /// <param name="spacing">The spacing.</param> /// <exception cref="System.ArgumentNullException">graphics</exception> public static void SetTextCharacterSpacing(Graphics graphics, int spacing) { graphics.ThrowIfNull(nameof(graphics)); IntPtr hdc = graphics.GetHdc(); SetTextCharacterExtra(hdc, spacing); graphics.ReleaseHdc(); }
/// <summary> /// Paints the month entries for day. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="datetime">The datetime.</param> /// <param name="cellRect">The cell rect.</param> /// <exception cref="System.ArgumentNullException">graphics</exception> protected override void PaintMonthEntriesForDay(Graphics graphics, DateTime datetime, Rectangle cellRect) { graphics.ThrowIfNull(nameof(graphics)); List<ScheduleEntry> todays = m_entries.Where(entry => entry.IsToday(datetime)).ToList(); // Sort Todays Entries Alphabetically todays.Sort(new ScheduleEntryTitleComparer()); Rectangle rect = cellRect; rect.X++; rect.Y += 14; rect.Width -= 1; rect.Height = 11; List<ScheduleEntry>.Enumerator e = todays.GetEnumerator(); if (!e.MoveNext()) return; while (e.Current != null) { ScheduleEntry entry = e.Current; if (entry is SimpleScheduleEntry) { // Setup a nice Brush Brush fillBrush = (entry.Options & ScheduleEntryOptions.Blocking) != 0 ? new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height), BlockingColor, SingleColor2) : new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height), SingleColor, SingleColor2); using (fillBrush) { // Check if the text fits Size textsize = TextRenderer.MeasureText(entry.Title, EntryFont); if (textsize.Width <= rect.Width) { graphics.FillRectangle(fillBrush, rect); TextRenderer.DrawText(graphics, entry.Title, EntryFont, new Point(rect.X + 1, rect.Y), TextColor); } else { // Make sure the text fits string shorttext = entry.Title + ".."; for (int i = entry.Title.Length - 1; i > 4; i--) { shorttext = entry.Title.Substring(0, i) + ".."; textsize = TextRenderer.MeasureText(shorttext, EntryFont); if (textsize.Width <= rect.Width) break; } graphics.FillRectangle(fillBrush, rect); TextRenderer.DrawText(graphics, shorttext, EntryFont, new Point(rect.X + 1, rect.Y), TextColor); } } } else if (entry is RecurringScheduleEntry) { // Setup a nice Brush Brush fillBrush = (entry.Options & ScheduleEntryOptions.Blocking) != 0 ? new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height), BlockingColor, RecurringColor2) : new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height), RecurringColor, RecurringColor2); using (fillBrush) { Size textsize = TextRenderer.MeasureText(entry.Title, EntryFont); if (textsize.Width <= rect.Width) { graphics.FillRectangle(fillBrush, rect); TextRenderer.DrawText(graphics, entry.Title, EntryFont, new Point(rect.X + 1, rect.Y), TextColor); } else { // Make sure the text fits string shorttext = entry.Title + ".."; for (int i = entry.Title.Length - 1; i > 4; i--) { shorttext = entry.Title.Substring(0, i) + ".."; textsize = TextRenderer.MeasureText(shorttext, EntryFont); if (textsize.Width <= rect.Width) break; } graphics.FillRectangle(fillBrush, rect); TextRenderer.DrawText(graphics, shorttext, EntryFont, new Point(rect.X + 1, rect.Y), TextColor); } } } rect.Y += rect.Height + 1; // Check if we have room for one more entry? if (rect.Y + rect.Height > cellRect.Y + cellRect.Height) { // No, are there more entries? if (e.MoveNext()) { // Yes, Draw something to let the user know int toomuch = rect.Y + rect.Height - (cellRect.Y + cellRect.Height); rect.Height -= toomuch; // Make sure LinearGradientBrush doesn't get into any troubles (Out Of Memory Because both points are at the same position) if (rect.Height == 0) rect.Height = 1; using ( Brush brush = new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X, rect.Y + rect.Height), Color.Gray, Color.LightGray)) { graphics.FillRectangle(brush, rect); } } break; } // Yes, we have more room e.MoveNext(); } }