Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error message: no overloading in a List

Status
Not open for further replies.

tobermory20

Programmer
Dec 7, 2007
20
US
I am having an issue with adding two elements to a list at the same time does anyone know how to make this happen or an alternative for it. I keep getting an error message about no overloading here is an example the JunkMonkey had helped with...
Code:
public List<Ellipse> lstEllipses = new List<Ellipse>();

public class Ellipse
{
  public int x;
  public int y;
  public int h = 25;
  public int w = 25;

  public void MyEllipse(int x, int y)
  {
     int X = x;
     int Y = y;
     //w = 25;
     //h = 25;

  }
  public void Draw(Graphics g)
  {
     g.DrawEllipse(new Pen(Color.Black, 2), x, y, w, h);
  }
}


//This adds a new ellipse at the clicked point. 
lstEllipses.Add(new Ellipse(e.X, e.Y));

Thank you,
T.
 
JurkMonkey this is what I meant.

Code:
//This adds a new ellipse at the clicked point.
lstEllipses.Add(new Ellipse(e.X, e.Y));

and actually it should be four arguments w and h, but the compiler is griping about overloading...
 
public class Ellipse
{
public int X;
public int Y;
public int Height = 25;
public int Width = 25;

//Notice that there is no return value on this method - it is the constructor. This allows you to call new Ellipse(x,y,w,h)
public Ellipse(int x, int y, int w, int h)
{
X = x;
Y = y;
Width = w;
Height = h;

}

public void Draw(Graphics g)
{
g.DrawEllipse(new Pen(Color.Black, 2), x, y, w, h);
}
}

 
Hey thanks for pointing that out, I saw what i did wrong... But I am getting this error now, how can correct this...

Cannot access a nonstatic member of outer type Form1 via nested type Form1.Ellipse
Code:
 public void Draw(Graphics g)
 {
      g.DrawEllipse(new Pen(Color.Black, 2), x, y, w, h);
 }
 
after hacking around with this portion of code

Code:
public class Ellipse
{
  public int X;
  public int Y;
  public int Height = 25;
  public int Width = 25;

//Notice that there is no return value on this method - it is the constructor. This allows you to call new Ellipse(x,y,w,h)
  public Ellipse(int x, int y, int w, int h)
  {
     X = x;
     Y = y;
     Width = w;
     Height = h;

  }

  public void Draw(Graphics g)
  {
     g.DrawEllipse(new Pen(Color.Black, 2), x, y, w, h);
  }
}

Here are the issues i continuly run into,
1. that Class Ellipse and public Ellipse are not allowed i guess
2. no overloading with above code in place(to many arguments)
Code:
 lstEllipses.Add(new Ellipse(e.X, e.Y, 100, 50))

Am I doing something wrong? Any help would be great...

Thank you,
T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top