当前位置: 首页>>代码示例>>C#>>正文


C# Graphics.ThrowIfNull方法代码示例

本文整理汇总了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++;
                    }
                }
            }
        }
开发者ID:RapidFiring,项目名称:evemon,代码行数:55,代码来源:PieChart.cs

示例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);
        }
开发者ID:RapidFiring,项目名称:evemon,代码行数:14,代码来源:Quadrilateral.cs

示例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);
                        }
                    }
//.........这里部分代码省略.........
开发者ID:RapidFiring,项目名称:evemon,代码行数:101,代码来源:ScheduleCalendar.cs


注:本文中的System.Drawing.Graphics.ThrowIfNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。