I want to create a class library which is able to draw pie or bar chart.
i’m using following codes…
Graphics g = CreateGraphics();
when i used that code visual studio told me you cant use with dll files(Class Library).
i’ve still problem how can i fix that… o_O
asking more information:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Data;
namespace KouChart
{
public class Pasta
{
public void PastaCiz(int a, int b, int c)
{
float toplam = a + b + c;
float deg1 = (a / toplam) * 360;
float deg2 = (b / toplam) * 360;
float deg3 = (c / toplam) * 360;
Pen p = new Pen(Color.Red, 2);
Graphics g = this.CreateGraphics();
Rectangle rec = new Rectangle(50, 12, 150, 150);
Brush b1 = new SolidBrush(Color.Red);
Brush b2 = new SolidBrush(Color.Black);
Brush b3 = new SolidBrush(Color.Blue);
Brush b4 = new SolidBrush(Color.Yellow);
g.DrawPie(p, rec, 0, deg1);
g.FillPie(b1, rec, 0, deg1);
g.DrawPie(p, rec, deg1, deg2);
g.FillPie(b2, rec, deg1, deg2);
g.DrawPie(p, rec, deg2 + deg1, deg3);
g.FillPie(b3, rec, deg2 + deg1, deg3);
}
}
}
and errors: Error 1 ‘KouChart.Pasta’ does not contain a definition for ‘CreateGraphics’ and no extension method ‘CreateGraphics’ accepting a first argument of type ‘KouChart.Pasta’ could be found (are you missing a using directive or an assembly reference?) C:\Users\Muyu\Documents\Visual Studio 2010\Projects\KouChart\KouChart\Pasta.cs 20 31 KouChart
The CreateGraphics() method belongs to the
Controlclass. IfPastais supposed to be a control, then you should derive it fromControl.i.e.
By the way, if you are writing a control, you would want to draw it in the OnPaint() method, and you don’t need to call
CreateGraphics()because one is already created for you. Here’s a very quick example to illustrate, but I’m not a control developer so please don’t consider this to be the correct approach.Also note that it would be more efficient to cache those
PenandBrushinstances instead of recreating them every time.