Help with this PieChart control
-
hi, I've been coding this PieChart control all day now, just couldn't get it to work, if you know how to write a custom control, plese help me. The main problem I have here is at the OnPaint() the PieChart doesn't draw all the pies except the first pie. What am I missing on writing a custom control here? Complete codes are below or you can download the project here PieChart.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;namespace ColorControl.Controls
{
public class PieChart : System.Windows.Forms.Control
{
// collection
private PieChartItemCollection _Items = new PieChartItemCollection();public PieChart() { base.Size = new Size(200, 200); SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true ); } public PieChartItemCollection Items { get { return \_Items; } set { \_Items = value; this.Invalidate(); } } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { int valueSum = 0; int startDegree = 0; int sweepDegree; // sum of values foreach (PieChartItem item in \_Items) { valueSum += (int)item.Value; } e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1); if (valueSum != 0) { // draw each pie foreach (PieChartItem item in \_Items) { // degree of each pie sweepDegree = (int)(item.Value / valueSum \* 360); SolidBrush brush = new SolidBrush(item.Color);
-
hi, I've been coding this PieChart control all day now, just couldn't get it to work, if you know how to write a custom control, plese help me. The main problem I have here is at the OnPaint() the PieChart doesn't draw all the pies except the first pie. What am I missing on writing a custom control here? Complete codes are below or you can download the project here PieChart.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;namespace ColorControl.Controls
{
public class PieChart : System.Windows.Forms.Control
{
// collection
private PieChartItemCollection _Items = new PieChartItemCollection();public PieChart() { base.Size = new Size(200, 200); SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true ); } public PieChartItemCollection Items { get { return \_Items; } set { \_Items = value; this.Invalidate(); } } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { int valueSum = 0; int startDegree = 0; int sweepDegree; // sum of values foreach (PieChartItem item in \_Items) { valueSum += (int)item.Value; } e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1); if (valueSum != 0) { // draw each pie foreach (PieChartItem item in \_Items) { // degree of each pie sweepDegree = (int)(item.Value / valueSum \* 360); SolidBrush brush = new SolidBrush(item.Color);
You should use Matrix transforms to rotate the drawing "canvas".
-
You should use Matrix transforms to rotate the drawing "canvas".