當前位置: 首頁>>代碼示例>>C#>>正文


C# Graphics.FillRect方法代碼示例

本文整理匯總了C#中System.Drawing.Graphics.FillRect方法的典型用法代碼示例。如果您正苦於以下問題:C# Graphics.FillRect方法的具體用法?C# Graphics.FillRect怎麽用?C# Graphics.FillRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Graphics的用法示例。


在下文中一共展示了Graphics.FillRect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DrawBattery

        private void DrawBattery(Graphics g, Rectangle rect)
        {
            g.ResetClip();
            g.ResetTransform();
            g.SetClip(rect);
            Point center = new Point(0, 0);
            int batteryTopHeight = rect.Height / 20;
            int batteryHeight = rect.Height - batteryTopHeight - 1;
            int batteryWidth = batteryHeight / 3;
            int batteryTopWidth = batteryWidth / 3;
            bool warning = BatteryLevel <= BatteryWarningLevel;

            // draw fill/level
            double batteryLevel = MathHelper.Clamp(BatteryLevel, 0.0, 1.0);
            int fill = (int)(batteryHeight * Math.Max(0.05, batteryLevel));
            g.FillRect(warning ? _brushWarning : _brush, center, 0.0, new Rectangle(0, batteryHeight - fill + batteryTopHeight, batteryWidth, fill));

            // draw outline
            g.DrawRect(_pen, center, 0.0, new Rectangle((batteryWidth - batteryTopWidth) / 2, 0, batteryTopWidth, batteryTopHeight));
            g.DrawRect(_pen, center, 0.0, new Rectangle(0, batteryTopHeight, batteryWidth, batteryHeight));

            // draw value
            StringFormat stringFormat = new StringFormat
            {
                Alignment = StringAlignment.Near,
                LineAlignment = StringAlignment.Far
            };
            g.DrawString((BatteryLevel * 100.0).ToString("000"), _font, warning ? _brushWarning : _brush, center, 0.0, new Point(batteryWidth + 5, rect.Height), stringFormat);
        }
開發者ID:joeferner,項目名稱:fivevolt,代碼行數:29,代碼來源:HudRenderer.cs

示例2: DrawBlade

        private void DrawBlade(Graphics g, Rectangle rect, double level)
        {
            g.ResetClip();
            g.ResetTransform();
            g.SetClip(rect);
            Point center = new Point(rect.Width / 2, rect.Height / 2);
            int barWidth = rect.Width / 5;
            int barHeight = (int)(rect.Width * 0.7);
            int radius = rect.Width / 2;
            double barOffset = Math.Cos(Math.Asin((barHeight / 2.0) / radius)) * radius;
            if (double.IsNaN(barOffset))
            {
                barOffset = 0;
            }

            // circle
            g.DrawEllipse(_pen, center, 0.0, new Rectangle(0, 0, rect.Width - 1, rect.Height - 1));

            // bar
            int fill = barHeight - (int)(barHeight * level);
            g.FillRect(_brush, center, 0.0, new Rectangle((int)(center.X - barOffset), (rect.Height - barHeight) / 2 + fill, barWidth, barHeight - fill));
            g.DrawRect(_pen, center, 0.0, new Rectangle((int)(center.X - barOffset), (rect.Height - barHeight) / 2, barWidth, barHeight));

            // text
            StringFormat stringFormat = new StringFormat
            {
                LineAlignment = StringAlignment.Center
            };
            g.DrawString((level * 100).ToString("00"), _font, _brush, center, 0.0, new Point((int)(center.X - barOffset + barWidth + 5), center.Y), stringFormat);
        }
開發者ID:joeferner,項目名稱:fivevolt,代碼行數:30,代碼來源:HudRenderer.cs

示例3: DrawBackground

 private void DrawBackground(Graphics g)
 {
     g.ResetClip();
     g.ResetTransform();
     g.SetClip(_rect);
     Point center = new Point(_rect.Width / 2, _rect.Height / 2);
     double roll = Roll;
     double scale = 12;
     double pitch = MathHelper.Rad2Deg(Pitch) * scale;
     int y = (int)(center.Y + pitch);
     g.FillRect(_skyBrush, center, roll, new Rectangle(0, 0, _rect.Width, y));
     g.FillRect(_groundBrush, center, roll, new Rectangle(0, y, _rect.Width, _rect.Height - y));
 }
開發者ID:joeferner,項目名稱:fivevolt,代碼行數:13,代碼來源:HudRenderer.cs


注:本文中的System.Drawing.Graphics.FillRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。