Board index » delphi » tpainbox and keyboard events

tpainbox and keyboard events

Hi!

I just wrote a small control-class which instances can be handled as simple
controls (like a self made button, etc.) that draw themselves in a TPaintBox
(with TPaintBox.Canvas).

Even when the PaintBox or the ScrollBox (in which the PaintBox is placed)
has the focus, I can't check the keyboard events, 'cause TPaintBox HAS NONE
! It only has mouse-event-handlers like OnMouseDown. But I need OnKeypressed
or OnKeydown like other classes (e.g. TForm) has them...

So how can I check the keyboard events in my TPaintBox?

Thanx
  Tobi

PS: By the way: using Delphi 3 Professional

 

Re:tpainbox and keyboard events


Write controls that paint on a TPaintBox ? I think you are missing the point
of the VCL.
Inherit your controls from TCustomControl and override the Paint method to
draw the control on the Canvas of the control. Now you can put these
controls directly on the form instead of using a TPaintBox !

"Tobias Hermann" <to...@mayn.de> schreef in bericht
news:959l6p$g5vhg$1@ID-38935.news.dfncis.de...

Quote
> Hi!

> I just wrote a small control-class which instances can be handled as
simple
> controls (like a self made button, etc.) that draw themselves in a
TPaintBox
> (with TPaintBox.Canvas).

> Even when the PaintBox or the ScrollBox (in which the PaintBox is placed)
> has the focus, I can't check the keyboard events, 'cause TPaintBox HAS
NONE
> ! It only has mouse-event-handlers like OnMouseDown. But I need
OnKeypressed
> or OnKeydown like other classes (e.g. TForm) has them...

> So how can I check the keyboard events in my TPaintBox?

> Thanx
>   Tobi

> PS: By the way: using Delphi 3 Professional

Re:tpainbox and keyboard events


hi! I changed the whole thing to TCustomControl.... VEEERY slow now !
Perhaps I missed some things of my old system... But the grafix output was
much much faster with my own system (drawing to the canvas of tpaintbox)...

what do you think?

 --> there are many many controls I have to create, about 400-500 small
controls. they are small cells with text ins it with different colours, etc.
nothing very special...

Thanx in advance..
  Tobi

Quote
> Write controls that paint on a TPaintBox ? I think you are missing the
point
> of the VCL.
> Inherit your controls from TCustomControl and override the Paint method to
> draw the control on the Canvas of the control. Now you can put these
> controls directly on the form instead of using a TPaintBox !

Re:tpainbox and keyboard events


Small cells with text in different colors ? Why not you use a TStringGrid
with OnDrawCell to draw colors/formatting ?

"Tobias Hermann" <to...@mayn.de> schreef in bericht
news:95cb6a$glsue$1@ID-38935.news.dfncis.de...

Quote
> hi! I changed the whole thing to TCustomControl.... VEEERY slow now !
> Perhaps I missed some things of my old system... But the grafix output was
> much much faster with my own system (drawing to the canvas of
tpaintbox)...

> what do you think?

>  --> there are many many controls I have to create, about 400-500 small
> controls. they are small cells with text ins it with different colours,
etc.
> nothing very special...

> Thanx in advance..
>   Tobi

> > Write controls that paint on a TPaintBox ? I think you are missing the
> point
> > of the VCL.
> > Inherit your controls from TCustomControl and override the Paint method
to
> > draw the control on the Canvas of the control. Now you can put these
> > controls directly on the form instead of using a TPaintBox !

Re:tpainbox and keyboard events


Hmm... The cells aren't all one next to the other... some lines have a bit
space bew{*word*249} them, some not (only a 1 pixel line)... Can I use different
cell widthes and heights with the stringgrid solution? I first thought of a
string grid but thought it wansn't flexible enough ? :-) Perhaps my
knowledge isn't that good and I don't know the componenst good enoght...

My solution is pretty fast and works fine but has no keyboard event handling
:-)

But perhaps I should check out the StringGrid component better (never did
ownerdraw things).

My problem is: I do things myself before looking into my delphi book if
something good already exists :-)

Tobi

Quote
> Small cells with text in different colors ? Why not you use a TStringGrid
> with OnDrawCell to draw colors/formatting ?

Re:tpainbox and keyboard events


If a TStringGrid isn't good enough for you, you will have to write your own
component (descendant of TCustomControl) that draws all the items on in
canvas and determines how mouse-clicks and button-presses should be handled.

"Tobias Hermann" <to...@mayn.de> schreef in bericht
news:95drn5$gvbmi$1@ID-38935.news.dfncis.de...

Quote
> Hmm... The cells aren't all one next to the other... some lines have a bit
> space bew{*word*249} them, some not (only a 1 pixel line)... Can I use different
> cell widthes and heights with the stringgrid solution? I first thought of
a
> string grid but thought it wansn't flexible enough ? :-) Perhaps my
> knowledge isn't that good and I don't know the componenst good enoght...

> My solution is pretty fast and works fine but has no keyboard event
handling
> :-)

> But perhaps I should check out the StringGrid component better (never did
> ownerdraw things).

> My problem is: I do things myself before looking into my delphi book if
> something good already exists :-)

> Tobi

> > Small cells with text in different colors ? Why not you use a
TStringGrid
> > with OnDrawCell to draw colors/formatting ?

Re:tpainbox and keyboard events


I did that, but I had many small instances of my descendant of
TCustomControl and this was slow.

Do you mean I should make ONE class that handles several cells in its ONE
canvas (so that not every cell is one instance of my control class, but I
have one instance of my control class and this draws the several cells
(perhaps an own class, not from tcustomcontrol)  on the correct positions on
its canvas ...) ?

Thanx
  Tobi

Quote
> If a TStringGrid isn't good enough for you, you will have to write your
own
> component (descendant of TCustomControl) that draws all the items on in
> canvas and determines how mouse-clicks and button-presses should be

handled.

Re:tpainbox and keyboard events


Yes, create ONE class that draws the 'controls' on its canvas. If you
derrive your class from TCustomControl it will be able to receive keyboard
focus (in contrast to a TGraphicControl descendant like TPaintBox).

"Tobias Hermann" <to...@mayn.de> schreef in bericht
news:95e2lc$hft2q$1@ID-38935.news.dfncis.de...

Quote
> I did that, but I had many small instances of my descendant of
> TCustomControl and this was slow.

> Do you mean I should make ONE class that handles several cells in its ONE
> canvas (so that not every cell is one instance of my control class, but I
> have one instance of my control class and this draws the several cells
> (perhaps an own class, not from tcustomcontrol)  on the correct positions
on
> its canvas ...) ?

> Thanx
>   Tobi

> > If a TStringGrid isn't good enough for you, you will have to write your
> own
> > component (descendant of TCustomControl) that draws all the items on in
> > canvas and determines how mouse-clicks and button-presses should be
> handled.

Re:tpainbox and keyboard events


thanx that works fine !! And I only had to change a bit of code --> not
drawing to painbox1.canvas but to the own canvas of my descendant class,
etc.
Quote
> Yes, create ONE class that draws the 'controls' on its canvas. If you
> derrive your class from TCustomControl it will be able to receive keyboard
> focus (in contrast to a TGraphicControl descendant like TPaintBox).

Other Threads