473,655 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ 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.Control Collection FormControls

{

get;

}

Cursor cursor

{

get;

set;

}

void SuspendLayout() ;

void ResumeLayout();

}
Aug 28 '07 #1
7 2347
On Aug 28, 10:41 am, "Rotsey"
<malcolm_sm...@ RemoveThis.optu snet.com.auwrot e:
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.co mwrote in message
news:11******** **************@ w3g2000hsg.goog legroups.com...
On Aug 28, 10:41 am, "Rotsey"
<malcolm_sm...@ RemoveThis.optu snet.com.auwrot e:
>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.optu snet.com.auwrot e:
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 PaintEventHandl er(PaintOnForm) ;
}

void PaintOnForm(obj ect 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.co mwrote in message
news:11******** **************@ r34g2000hsd.goo glegroups.com.. .
On Aug 28, 12:20 pm, "Rotsey"
<malcolm_sm...@ RemoveThis.optu snet.com.auwrot e:
>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.co mwrote in message
news:11******** **************@ w3g2000hsg.goog legroups.com...
On Aug 28, 10:41 am, "Rotsey"
<malcolm_sm...@ RemoveThis.optu snet.com.auwrot e:
>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.optu snet.com.auwrot e:
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 PaintEventHandl er

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.co mwrote in message
news:11******** **************@ y42g2000hsy.goo glegroups.com.. .
On Aug 28, 1:15 pm, "Rotsey"
<malcolm_sm...@ RemoveThis.optu snet.com.auwrot e:
>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
3181
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 forms... I tried painting, but the paintaing area provided by the form is only the client area - no visible way to paint on the title bar.
2
7671
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 like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
4
2169
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
3718
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 the Controls.Add() method several times or even calling the Controls.AddRange() method once can take a huge amount of time. Therefore, I would like to be able to run the loop that creates the controls on a different thread and meanwhile give the user...
7
1682
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 inherit it in all my other forms, but a simple event link? if that is the right term would be easier? Thx.
6
3141
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 works fine, it seems to fire when the form changes visibility. Here is the code. Private Sub lblP1JoyUp_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles lblP1JoyUp.Paint If lblP1JoyUp.Visible = True Then Dim...
7
1823
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 question is..how would I save the tif images as soon as it is initially painted, and then restore the image in a paint event. It seems to me that there should be some sort of a SaveImage method and a RestoreImage method that would be fast. Note:...
4
4889
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 behavior? Is it possible to prevent that? Thanks.
5
2090
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. Normally I put my updation of data shown in the controls on the usercontrol in the Paint event handler of the usercontrol. When it comes to the radiobuttons, a paint event for the usercontrol is fired whenever hovering over the radiobuttons, making...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8598
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2721
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 we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.