Developer technologies | Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace My_Pie
{
public partial class Form1 : Form
{
int myPiePercent = 15;
public Form1()
{
InitializeComponent();
timer1.Enabled = true;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Green, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1);
DrawPieOnPicturebox(e.Graphics);
}
public void DrawPieOnPicturebox(Graphics myPieGraphic)
{
Color myPieColors = Color.LightGreen;
Point myPieLocation = new Point(pictureBox1.ClientRectangle.Width / 2,
pictureBox1.ClientRectangle.Height / 2);
Size myPieSize = new Size(150, 150);
DrawMyPie(myPiePercent, myPieColors, myPieGraphic, myPieLocation, myPieSize);
}
public void DrawMyPie(int myPiePerecent, Color myPieColor, Graphics myPieGraphic, Point
myPieLocation, Size myPieSize)
{
using (SolidBrush brush = new SolidBrush(myPieColor))
{
myPieGraphic.FillPie(brush, new Rectangle(myPieLocation, myPieSize), Convert.ToSingle(myPiePerecent * 360 / 100), Convert.ToSingle(15 * 360 / 100));
}
}
private void timer1_Tick(object sender, EventArgs e)
{
myPiePercent++;
pictureBox1.Invalidate();
}
}
}
Check some modifications:
public void DrawPieOnPicturebox( Graphics myPieGraphic )
{
Color myPieColors = Color.LightGreen;
Size myPieSize = new Size( 150, 150 );
Point myPieLocation = new Point( ( pictureBox1.ClientRectangle.Width - myPieSize.Width ) / 2, ( pictureBox1.ClientRectangle.Height - myPieSize.Height ) / 2 );
DrawMyPie( myPiePercent, myPieColors, myPieGraphic, myPieLocation, myPieSize );
}