當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。