当前位置: 首页>>代码示例>>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;未经允许,请勿转载。