adding a Paint event to a interface

  • Thread starter Thread starter Rotsey
  • Start date Start date
R

Rotsey

Hi,

I have a interface that I use for a form so I can pass the form
to another object.

How do I add the Paint event to the interface and subsequently
handle the paint event in my other object.?

I am not sure of the syntax required to do this?

Could you please give an example?

thanks
rotsey




public interface IForm

{

TabControl TabPageControl

{

get;

set;

}

Control.ControlCollection FormControls

{

get;

}

Cursor cursor

{

get;

set;

}

void SuspendLayout();

void ResumeLayout();

}
 
I have a interface that I use for a form so I can pass the form
to another object.

How do I add the Paint event to the interface and subsequently
handle the paint event in my other object.?

Declare the Paint event in the interface:

public event EventHandler Paint;

(or whatever).

Then implement the event in your form in the normal way (either with a
field-like event as above, or with explicit add/remove methods).

Jon
 
I partly see what you mean.

I added the line and then get errors saying form does not implement paiint
so I added

void Paint(object sender, PaintEventArgs e)

{

}

Then I get error "paint hides inherited member System.Windows.Form.Paint

???

I thought that after adding your line that the forms as they have a Paint
event already would be ok.

What i want to do is implement the Paint event once in
my object that gets passed the IForm object???
Not in every form that implements IForm.

help
 
I partly see what you mean.

I added the line and then get errors saying form does not implement paiint
so I added

void Paint(object sender, PaintEventArgs e)
{

}

Then I get error "paint hides inherited member System.Windows.Form.Paint

Well, that's a method rather than an event. For clarity, it would
probably be worth renaming your event.
???

I thought that after adding your line that the forms as they have a Paint
event already would be ok.

No - just because a base class has something which appears to
implement part of an interface doesn't mean that the derived class can
use it if that's where the interface is introduced.
What i want to do is implement the Paint event once in
my object that gets passed the IForm object???
Not in every form that implements IForm.

Sure sure exactly what you mean there, I'm afraid.

Jon
 
I am confused Jon but I will not give up

Let give the bare bones code and you can tell me where
went wrong

Interface IForm
{
public event EventHandler Paint;

}

class MyForm1 : IForm
{
//what goes here
}

class MyForm2 : IForm
{
//what goes here to satisfy interface
}

class MyObject
{
void MyObject(IForm form)
{
form.Paint += new PaintEventHandler(PaintOnForm);
}

void PaintOnForm(object sender, PaintEventArgs e)
{
//Draw things
}
}


So if that is right then all i am not sure about is how to
define the Paint event in MyForm1 and MyForm2 to satisfy
the interface???

Appreciate the help Jon.

rotsey
 
I am confused Jon but I will not give up

Let give the bare bones code and you can tell me where
went wrong

Interface IForm
{
public event EventHandler Paint;

}

class MyForm1 : IForm
{
//what goes here
}

You need to introduce a new Paint event. As I said before, it's
probably best to rename it so as not to get confused between
Control.Paint and IForm.Paint.
So if that is right then all i am not sure about is how to
define the Paint event in MyForm1 and MyForm2 to satisfy
the interface???

You could either introduce a new Paint event like this:

public new event EventHandler Paint
{
add { base.Paint += value; }
remove { base.Paint -= value; }
}

so that a subscription to the "new" Paint event just subscribes to the
Control.Paint event.

Alternatively, you could change the name of the event in the interface
to MyPaint or whatever.
Appreciate the help Jon.

No problem.

Jon
 
I see but I just got it working by just changing
the line you orignally gave me from

EventHandler to PaintEventHandler

which means the base form already defines that event
which is what I wanted

and it works great.

thanks for all your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top