BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Paint on form

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing
View previous topic :: View next topic  
Author Message
Martin Venter
Guest





PostPosted: Wed Nov 19, 2003 12:31 pm    Post subject: Paint on form Reply with quote



Hi Everyone,

I'm posting this question again because my date was incorrectly set on my
computer.

Hope someone can help me. Here is the story.

I created a custom component that inherits from TCustomPanel called
TCustomIVRControl.

One of the properties of the component is Destination and it is of type
TCustomIVRControl.

When Destination is set to a control I then draw a line on the form canvas
to the Destination control.



The controls can also be dragged around the form at runtime. When this
happens the controls need to redraw their lines. Currently only the control
being dragged correctly repaints the lines. The rest of the controls lose
there lines. The code that draws the lines is in the WMPaint procedure.

Obviously this is the wrong place. Where would be the correct procedure to
place this code? I thought about hooking my draw procedure onto the forms
OnPaint event but I can have any number of these controls on my form. Surely
not all of them can hook onto this event or can they?



Any help would be appreciated.


Regards,
Martin


Back to top
Kurt Barthelmess
Guest





PostPosted: Wed Nov 19, 2003 1:32 pm    Post subject: Re: Paint on form Reply with quote



"Martin Venter" <martin (AT) unirnd (DOT) co.za> wrote:

First, you might want to check the time and date on your system. This
post was marked Sun, 19 Oct 2003 14:22:04 +0200.

Quote:
When Destination is set to a control I then draw a line on the form canvas
to the Destination control.

That's a problem. Drawing outside your window makes for difficult
times doing a refresh as you've found.

Quote:
The controls can also be dragged around the form at runtime. When this
happens the controls need to redraw their lines. Currently only the control
being dragged correctly repaints the lines. The rest of the controls lose
there lines. The code that draws the lines is in the WMPaint procedure.

But it draws on the Parent's canvas, right?

Quote:
Obviously this is the wrong place. Where would be the correct procedure to
place this code? I thought about hooking my draw procedure onto the forms
OnPaint event but I can have any number of these controls on my form. Surely
not all of them can hook onto this event or can they?

You can't do it via OnPaint. There's only one method there, and it may
be being used by the Parent anyhow. One solution would be to provide
an event handler in your component that the Parent can call to let the
component redraw its stuff. But that requires code in the Parent to
iterate through its compnents to call each component's event.

Another solution would be to have your components be dropped on a
secondary, containing, component ala TPanel. This component then can
provide all the coordination and the Canvas for inter-component
drawing. To be honest, that's going to be ugly to implement, but I
don't see any clean way to do this - you've broken the fundamental
rule of drawing - do it only within your own window.

Good luck.

Kurt


Back to top
Roberto Scardovi
Guest





PostPosted: Thu Nov 20, 2003 8:29 am    Post subject: Re: Paint on form Reply with quote



Correct...

but, IMO, you should not try to give your control the responsibilty to
draw outside of itself (in the form canvas). This is not OO compliant
and very tricky...

Create instead an additional (transparent) panel with the ability
do draw a diagonal line INSIDE of itself and create an instance
of such control in the form when you need it, giving it the position
you need to get the "line" displayed where you want it.

Isn't it cleaner ?

Roberto

www.erzensoft.com


[email]kbarthelmess (AT) compuserve (DOT) com[/email] (Kurt Barthelmess (TeamB)) wrote in message news:<3fbb6eb3.3889452 (AT) newsgroups (DOT) borland.com>...
Quote:
"Martin Venter" <martin (AT) unirnd (DOT) co.za> wrote:

First, you might want to check the time and date on your system. This
post was marked Sun, 19 Oct 2003 14:22:04 +0200.

When Destination is set to a control I then draw a line on the form canvas
to the Destination control.

That's a problem. Drawing outside your window makes for difficult
times doing a refresh as you've found.

The controls can also be dragged around the form at runtime. When this
happens the controls need to redraw their lines. Currently only the control
being dragged correctly repaints the lines. The rest of the controls lose
there lines. The code that draws the lines is in the WMPaint procedure.

But it draws on the Parent's canvas, right?

Obviously this is the wrong place. Where would be the correct procedure to
place this code? I thought about hooking my draw procedure onto the forms
OnPaint event but I can have any number of these controls on my form. Surely
not all of them can hook onto this event or can they?

You can't do it via OnPaint. There's only one method there, and it may
be being used by the Parent anyhow. One solution would be to provide
an event handler in your component that the Parent can call to let the
component redraw its stuff. But that requires code in the Parent to
iterate through its compnents to call each component's event.

Another solution would be to have your components be dropped on a
secondary, containing, component ala TPanel. This component then can
provide all the coordination and the Canvas for inter-component
drawing. To be honest, that's going to be ugly to implement, but I
don't see any clean way to do this - you've broken the fundamental
rule of drawing - do it only within your own window.

Good luck.

Kurt

Back to top
Martin Venter
Guest





PostPosted: Fri Nov 21, 2003 10:54 am    Post subject: Re: Paint on form Reply with quote

Hi Kurt,

Thanks for letting me know about the date problem.

Let me explain again. When I run the application the painting is done right
but once I move a
control only that control repaints correctly. If I minimize the form to the
taskbar and then display it again the repainting is done correctly.

If anyone knows of a good way to handle this repainting I'm all ears.

I did however figure out a method that works but it may not be the best one.

Here is what I did:
The Notification procedure of TControl gave me an Idea. Basically when a
control gets deleted it calls the Notification procedure of all the other
controls to let them know it is being deleted.

Using that idea I added a PaintNotification procedure. This procedure draws
the lines for the control. So when my control gets moved I call the
PaintNotification procedure of all the other controls. It works great.

Any comments would be appreciated.

Regards,

Martin

"Kurt Barthelmess (TeamB)" <kbarthelmess (AT) compuserve (DOT) com> wrote

Quote:
"Martin Venter" <martin (AT) unirnd (DOT) co.za> wrote:

First, you might want to check the time and date on your system. This
post was marked Sun, 19 Oct 2003 14:22:04 +0200.

When Destination is set to a control I then draw a line on the form
canvas
to the Destination control.

That's a problem. Drawing outside your window makes for difficult
times doing a refresh as you've found.

The controls can also be dragged around the form at runtime. When this
happens the controls need to redraw their lines. Currently only the
control
being dragged correctly repaints the lines. The rest of the controls lose
there lines. The code that draws the lines is in the WMPaint procedure.

But it draws on the Parent's canvas, right?

Obviously this is the wrong place. Where would be the correct procedure
to
place this code? I thought about hooking my draw procedure onto the forms
OnPaint event but I can have any number of these controls on my form.
Surely
not all of them can hook onto this event or can they?

You can't do it via OnPaint. There's only one method there, and it may
be being used by the Parent anyhow. One solution would be to provide
an event handler in your component that the Parent can call to let the
component redraw its stuff. But that requires code in the Parent to
iterate through its compnents to call each component's event.

Another solution would be to have your components be dropped on a
secondary, containing, component ala TPanel. This component then can
provide all the coordination and the Canvas for inter-component
drawing. To be honest, that's going to be ugly to implement, but I
don't see any clean way to do this - you've broken the fundamental
rule of drawing - do it only within your own window.

Good luck.

Kurt





Back to top
Kurt Barthelmess
Guest





PostPosted: Fri Nov 21, 2003 2:02 pm    Post subject: Re: Paint on form Reply with quote

"Martin Venter" <martin (AT) unirnd (DOT) co.za> wrote:

Quote:
Let me explain again. When I run the application the painting is done right
but once I move a
control only that control repaints correctly. If I minimize the form to the
taskbar and then display it again the repainting is done correctly.

That seems reasonable. Everybody got called to redraw themselves.

Quote:
If anyone knows of a good way to handle this repainting I'm all ears.

The problem is that your components all need to be notified of
repainting rquirements. Your notification technique below is
innovative, and will handle the situation where a component is
deleted. Generally speaking, though, I don't think this is enough.
Suppose you have two components, A and B with a four inch line between
them. A popup (from another application, say) jumps up, overwriting a
portion of that line. You close it. Now a portion of the line between
A and B needs to be repainted. But only the container (the form) gets
asked to repaint. Neither A nor B is asked to repaint because the
popup did not touch them.

That's a specific case of the general problem, which is that none of
your components "own" the space around them and on which they are
drawing. So when it needs to be redrawn (as often happens), nothing
notifies them. That's why I suggested an underlying container panel or
something that would hold all your components and "own" the space
between them. Then it will be told to repaint, and can ask the
children to do so.

Good luck.

Kurt


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.