473,472 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

adding a Paint event to a interface

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();

}
Aug 28 '07 #1
7 2330
On Aug 28, 10:41 am, "Rotsey"
<malcolm_sm...@RemoveThis.optusnet.com.auwrote:
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

Aug 28 '07 #2
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
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
On Aug 28, 10:41 am, "Rotsey"
<malcolm_sm...@RemoveThis.optusnet.com.auwrote:
>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

Aug 28 '07 #3
On Aug 28, 12:20 pm, "Rotsey"
<malcolm_sm...@RemoveThis.optusnet.com.auwrote:
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

Aug 28 '07 #4
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

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@r34g2000hsd.googlegr oups.com...
On Aug 28, 12:20 pm, "Rotsey"
<malcolm_sm...@RemoveThis.optusnet.com.auwrote:
>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

Aug 28 '07 #5
I forgot MyForm1 and MyForm2 also implement
System.Windows.Form

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
On Aug 28, 10:41 am, "Rotsey"
<malcolm_sm...@RemoveThis.optusnet.com.auwrote:
>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

Aug 28 '07 #6
On Aug 28, 1:15 pm, "Rotsey"
<malcolm_sm...@RemoveThis.optusnet.com.auwrote:
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

Aug 28 '07 #7
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
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
On Aug 28, 1:15 pm, "Rotsey"
<malcolm_sm...@RemoveThis.optusnet.com.auwrote:
>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

Aug 28 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Picho | last post by:
Hi all, Is there any .NET way (I am not rulling out API usage) to add button(s) to a form's title bar? I found some non-.NET solutions that did actually work in VB6 but not in the ..NET...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
4
by: Tamir Khason | last post by:
Why when I lost focus (go to back) on form all GDI+ paints disappears..... BUG or I do something wrong???? TNX
2
by: avivgur | last post by:
Hello, I am writing a program in Visual C# and I have encountered a problem. In my program I want to dynamically create a multitude of controls (thousands) on a form. The problem is that calling...
7
by: Schorschi | last post by:
I know there is a way to do this, but I don't know how. Via a custom event? I have some code that I only want to run during a paint event. I could build a form instance that has the code and...
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
7
by: hamil | last post by:
The following code will display a tif file on a form. When another form is moved over the tif image, the tif image is erased where the form was moved. A paint event occurs when this happens. My...
4
by: Kürþat | last post by:
Hi all, I do some drawing in a form's paint event handler and I have a button on that form. Whenever the mouse enters or leaves the button Form's paint event occurs. Isn't that a strange...
5
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, On a usercontrol I've put a set of radiobuttons within a groupbox. These radiobuttons have visual style enables, i.e. they turn orange when hovering over them and green when pushed. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.