Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:34:41+00:00 2026-05-27T05:34:41+00:00

I want to create a class library which is able to draw pie or

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:34:42+00:00Added an answer on May 27, 2026 at 5:34 am

    The CreateGraphics() method belongs to the Control class. If Pasta is supposed to be a control, then you should derive it from Control.

    i.e.

    public class Pasta : Control
    {
        public void PastaCiz(int a, int b, int c)          
        { ... }
    }
    

    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.

    public class Pasta : Control
    {
        int a;
        int b;
        int c;
    
        public void PastaCiz(int a, int b, int c)
        {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            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 = e.Graphics;                           <-- note
            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);
        }
    }
    

    Also note that it would be more efficient to cache those Pen and Brush instances instead of recreating them every time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create a class library project which will my data access layer
I want to create a class that initializes a timer which will be used
I want to create a Class, say MyDiv , which inherits from the original
I want to create a C++ class with the following type: It can be
I want to create a class with a nested enum. public class Foo {
I want to create whois class like that public class DomainInfo { public string
NET MVC and i want to create a class to contain site wide functions
I have a question regarding dependency injection. say i want to create a class
I'm having a problem with curl_multi_* , I want to create a class /
I want to create a static class in PHP and have it behave like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.