user3458123
user3458123

Reputation: 23

Send drawing from a class to a form in C#

I have a class named CircleSector which draws a PIChart.

I am unable to draw the PIChart if I call the Class from form1.

Here is my code:

Form1:

public void button1_Click(object sender, EventArgs e)
{
    int textdata = Convert.ToInt32(textBox1.Text);
    CS = new CircleSector(textdata, this);
    // CS.GetGraphicSector(this);
}

CircleSector:

public CircleSector(int TextData , Form1 D)
{
    Pen CirclePen = new Pen(Color.Black);
    Rect = new Rectangle(XAxis, YAxis, CircleRadius, CircleRadius);
    float temp1 = 0;
    SectorCircle = this.CreateGraphics();
    PIVal = - 360 / TextData;

    float temp2 = PIVal;
    for (int i = 0; i <= TextData; i++)
    {
        m_Value = i;
        SectorCircle.DrawPie(CirclePen, Rect, 0, temp2);
        temp1 = temp2;
        temp2 = temp2 - PIVal;
    }

    //  MessageBox.Show("Mouse Pressed");
    //  return SectorCircle;
}

Upvotes: 2

Views: 51

Answers (1)

Shell
Shell

Reputation: 6849

I think the problem is here.

SectorCircle = this.CreateGraphics();

try this.

SectorCircle = D.CreateGraphics();

Upvotes: 1

Related Questions