本文整理汇总了C#中System.Drawing.Graphics.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.ThrowIfNull方法的具体用法?C# Graphics.ThrowIfNull怎么用?C# Graphics.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.ThrowIfNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlaceTexts
/// <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++;
}
}
}
}
示例2: Draw
/// <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);
}
示例3: PaintMonthEntriesForDay
/// <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);
}
}
//.........这里部分代码省略.........