System.Drawing.Graphics.FillRegion C# (CSharp) Method

FillRegion() public method

Fills the interior of a region.
public FillRegion ( Brush brush, Region region ) : void
brush Brush Brush.
region Region Region.
return void
        public void FillRegion(Brush brush, Region region)
        {
            if (brush == null)
                throw new ArgumentNullException ("brush");
            if (region == null)
                throw new ArgumentNullException ("region");

            // We will clear the rectangle of our clipping bounds for Empty
            if (region.regionPath == null)
            {
                // This may set the rectangle to Black depending on the context
                // passed.  On a NSView set WantsLayers and the Layer Background color.
                context.ClearRect (context.GetClipBoundingBox ());
                return;
            }

            context.AddPath (region.regionPath);
            FillBrush (brush);
        }

Usage Example

        public static void UpDateChargingIcon(double BatteryVoltage, bool OffLine)
        {
            int PercentageBattery = Convert.ToInt32(((BatteryVoltage - UPS_Manager.Properties.Settings.Default.BatteryChargeMin) / ((UPS_Manager.Properties.Settings.Default.BatteryChargeMax - 0.1) - UPS_Manager.Properties.Settings.Default.BatteryChargeMin)) * 100);

            if (PercentageBattery <= 100 && !OffLine)
            {
                System.Drawing.Font       drawFont         = new System.Drawing.Font("Webdings", 70, FontStyle.Regular);
                System.Drawing.Font       drawFont1        = new System.Drawing.Font("Webdings", 85, FontStyle.Bold);
                System.Drawing.SolidBrush DrawBrushEmpty   = new System.Drawing.SolidBrush(System.Drawing.Color.Transparent);
                System.Drawing.SolidBrush DrawBrushSymbol  = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                System.Drawing.SolidBrush DrawBrushSymbol1 = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                System.Drawing.SolidBrush DrawBrushFull    = new System.Drawing.SolidBrush(System.Drawing.Color.White);

                Bitmap bitmap = new Bitmap(100, 100); // new Bitmap(100, 100);
                System.Drawing.Graphics  graphics      = System.Drawing.Graphics.FromImage(bitmap);
                System.Drawing.Rectangle DrawRectRed   = new Rectangle(0, 100 - PercentageBattery, 100, PercentageBattery);
                System.Drawing.Region    DrawRegionRed = new System.Drawing.Region(DrawRectRed);
                graphics.FillRegion(DrawBrushFull, DrawRegionRed);
                System.Drawing.Rectangle DrawRectGreen   = new Rectangle(0, 0, 100, 100 - PercentageBattery);
                System.Drawing.Region    DrawRegionGreen = new System.Drawing.Region(DrawRectGreen);
                graphics.FillRegion(DrawBrushEmpty, DrawRegionGreen);
                graphics.DrawString("~", drawFont1, DrawBrushSymbol1, -22, -3);
                graphics.DrawString("~", drawFont, DrawBrushSymbol, -8, 0);
                Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());

                UPSNotifyIcon.Icon = createdIcon;
                UPSNotifyIcon.Text = " " + PercentageBattery.ToString() + "%" + System.Environment.NewLine + BatteryVoltage.ToString() + "V";
            }
            else
            {
                UPSNotifyIcon.Icon = Properties.Resources.OnLine;
                UPSNotifyIcon.Text = BatteryVoltage.ToString() + "V";
            }
        }
All Usage Examples Of System.Drawing.Graphics::FillRegion