9 Replies - 6177 Views - Last Post: 04 May 2009 - 11:34 PM Rate Topic: -----

#1 zflowerz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-April 09

Getting a overload error

Posted 01 May 2009 - 06:17 AM

this is the error i get

Error 1 No overload for 'Form1_Paint' matches delegate 'System.Windows.Forms.PaintEventHandler' C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\paint test 2\Form1.Designer.cs 41 27 paint test 2

what is to overload, and how do i do this?

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace paint_test_2
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		public string teXt;
		private void Form1_Load(object sender, EventArgs e)
		{
			string file_name = "c:\\temp\\test.txt";
			{
				System.IO.StreamReader objReader;
				objReader = new System.IO.StreamReader(file_name);

				//textBox1.Text = objReader.ReadToEnd();
				teXt = objReader.ReadToEnd();
				objReader.Close();
			}
		}
		private void Form1_Paint(Graphics g, string text, int scroll, float text_width)
		{
			int count = (int)(this.ClientSize.Width / text_width + .5f) + 1;
			int sc = (int)(scroll % text_width);
			for (int i = 0; i < count; i++)
			{
				g.DrawString(teXt, this.Font, Brushes.Black, i * text_width - sc, 0);
			}

  
		}
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Getting a overload error

#2 SixOfEleven   User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Getting a overload error

Posted 01 May 2009 - 07:03 AM

View Postzflowerz, on 1 May, 2009 - 05:17 AM, said:

this is the error i get

Error 1 No overload for 'Form1_Paint' matches delegate 'System.Windows.Forms.PaintEventHandler' C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\paint test 2\Form1.Designer.cs 41 27 paint test 2

what is to overload, and how do i do this?

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace paint_test_2
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		public string teXt;
		private void Form1_Load(object sender, EventArgs e)
		{
			string file_name = "c:\\temp\\test.txt";
			{
				System.IO.StreamReader objReader;
				objReader = new System.IO.StreamReader(file_name);

				//textBox1.Text = objReader.ReadToEnd();
				teXt = objReader.ReadToEnd();
				objReader.Close();
			}
		}
		private void Form1_Paint(Graphics g, string text, int scroll, float text_width)
		{
			int count = (int)(this.ClientSize.Width / text_width + .5f) + 1;
			int sc = (int)(scroll % text_width);
			for (int i = 0; i < count; i++)
			{
				g.DrawString(teXt, this.Font, Brushes.Black, i * text_width - sc, 0);
			}

  
		}
	}
}



An overload is where you have more the one method by the same name but the parameters passed to it are different. This is an example of an overload.

public void myMethod(int x)
{
}

public void myMethod(int x, string myString)
{
}



It is a concept known as polymorphism.

Your problem is you added a new variable to the Form1_Paint method. I don't think you can just do that you would probably want to remove the Graphics parameter and create a Graphics object inside the method or create a global Graphics object inside the class.

*edit* missed a word in there.

This post has been edited by SixOfEleven: 01 May 2009 - 07:54 AM

Was This Post Helpful? 0
  • +
  • -

#3 beatles1692   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 62
  • Joined: 03-December 08

Re: Getting a overload error

Posted 02 May 2009 - 01:07 PM

Hi!
It seems that you want to handle the Paint event of a form.To handle an event you must attach a suitable event handler to it(using += operator) .Each event has a delegate definition as its handler type.For example Click event of many controls (like Button) has a System.EventHandler type as its delegate that has a signature like this:
delegate void EventHandler(object sender,EventArgs e);


So if you want to handle this event you should attach it to a method with the same signature:
private void Buttonclicked(object sender,EventArgs e)
{

}


Then you should take a look at System.Windows.Forms.PaintEventHandler and find out its signature and use a method with same signature to handle the paint event.

This post has been edited by beatles1692: 02 May 2009 - 01:09 PM

Was This Post Helpful? 0
  • +
  • -

#4 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Getting a overload error

Posted 02 May 2009 - 02:00 PM

View PostSixOfEleven, on 1 May, 2009 - 07:03 AM, said:

It is a concept known as polymorphism.



No it is not:

Quote

Polymorphism is not the same as method overloading or method overriding.

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Getting a overload error

Posted 02 May 2009 - 02:27 PM

Actually, KYA I think that there are people out there that consider what we would traditionally refer to as polymorphism as runtime polymorphism, while operator overloading is considered a means of compile-time polymorphism. It's all programming to me...I let the language lawyers deal with it :)
Was This Post Helpful? 0
  • +
  • -

#6 SixOfEleven   User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Getting a overload error

Posted 02 May 2009 - 04:09 PM

I agree that overloading is not the end all of polymorphism, it is an aspect of polymorphism. The program works differently in different contexts.

I found this on polymorphism:

Quote

In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.


*edit*
But this would probably better discussed in the computer science forum.

*edit again*
This is probably a better description:

Quote

In simple terms, polymorphism is the ability of one type, A, to appear as and be used like another type, B. In strongly typed languages, this usually means that type A somehow derives from type B, or type A implements an interface that represents type B.

This post has been edited by SixOfEleven: 02 May 2009 - 04:18 PM

Was This Post Helpful? 0
  • +
  • -

#7 SixOfEleven   User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Getting a overload error

Posted 02 May 2009 - 07:35 PM

I found a better way to describe polymorphism to those new to C#.

Quote

Through inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. This is called polymorphism. In C#, every type is polymorphic. Types can be used as their own type or as a Object instance, because any type automatically treats Object as a base type.

Was This Post Helpful? 0
  • +
  • -

#8 LycHaf17   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-May 09

Re: Getting a overload error

Posted 03 May 2009 - 01:37 PM

View PostSixOfEleven, on 2 May, 2009 - 06:35 PM, said:

I found a better way to describe polymorphism to those new to C#.

Quote

Through inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. This is called polymorphism. In C#, every type is polymorphic. Types can be used as their own type or as a Object instance, because any type automatically treats Object as a base type.


That's what I've been taught polymorphism is in C# and C++. I might be going out on a limb here, but you might have an event handler without a declared event. Try checking if you have all events and event handlers matched up.
Was This Post Helpful? 0
  • +
  • -

#9 SixOfEleven   User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Getting a overload error

Posted 03 May 2009 - 02:13 PM

View PostLycHaf17, on 3 May, 2009 - 12:37 PM, said:

View PostSixOfEleven, on 2 May, 2009 - 06:35 PM, said:

I found a better way to describe polymorphism to those new to C#.

Quote

Through inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. This is called polymorphism. In C#, every type is polymorphic. Types can be used as their own type or as a Object instance, because any type automatically treats Object as a base type.


That's what I've been taught polymorphism is in C# and C++. I might be going out on a limb here, but you might have an event handler without a declared event. Try checking if you have all events and event handlers matched up.


The problem is that event handlers are expected to have a certain format you can't just create new formats for the handlers. They are expected to have an Object sender and some type of EventArgs e. You can't just add another parameter to the handler.
Was This Post Helpful? 0
  • +
  • -

#10 LycHaf17   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-May 09

Re: Getting a overload error

Posted 04 May 2009 - 11:34 PM

View PostSixOfEleven, on 3 May, 2009 - 01:13 PM, said:

View PostLycHaf17, on 3 May, 2009 - 12:37 PM, said:

View PostSixOfEleven, on 2 May, 2009 - 06:35 PM, said:

I found a better way to describe polymorphism to those new to C#.

Quote

Through inheritance, a class can be used as more than one type; it can be used as its own type, any base types, or any interface type if it implements interfaces. This is called polymorphism. In C#, every type is polymorphic. Types can be used as their own type or as a Object instance, because any type automatically treats Object as a base type.


That's what I've been taught polymorphism is in C# and C++. I might be going out on a limb here, but you might have an event handler without a declared event. Try checking if you have all events and event handlers matched up.


The problem is that event handlers are expected to have a certain format you can't just create new formats for the handlers. They are expected to have an Object sender and some type of EventArgs e. You can't just add another parameter to the handler.


Ah. yes. I do know that you shouldn't mess with the parameters, can't say i've ever had a need to. I didn't realize that's the problem. Well now i can say I learned something today :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1