Board index » cppbuilder » TImage wheel handling

TImage wheel handling


2005-04-05 07:04:48 PM
cppbuilder1
I've got a TImage component and I want to be able to catch OnMouseWheelUp
and OnMouseWheelDown events, so I could force zooming with the mouse wheel.
The problem is that TImage is not a TWinControl descendant and thus cannot
receive focus. I tried putting the Image into a tScrollBox component which
can receive focus and has OnMouseWheel events published and tried putting my
code there but nothing happens (and I guess it shouldn't cause Image1->Align
is alClient and so the whole client area of the ScrollBox is occupied with
the Image). I also derived a new component from TImage and published the
wheel events but this also didn't work. How can I solve this problem? Thank
you.
 
 

Re:TImage wheel handling

Analian wrote:
Quote
The problem is that TImage is not a TWinControl descendant and thus
cannot receive focus.
What I did in a simlar situation was use a TEdit sitting underneath a
panel. I left its Visible property set to true and it takes care of
keyboard/visual focus issues for me.
Quote
I've got a TImage component and I want to be able to catch
OnMouseWheelUp and OnMouseWheelDown events, so I could force zooming
with the mouse wheel.
The handlers for these events are members of TForm. I confess to never
having used them but it seems logical for them to be there. Have you
had problems with them?
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:TImage wheel handling

Hi,
In addition to Andrue's comments, if you want to perform zooming with
the TImage, you'll need to set the Stretch property to true, and then
adjust the Width and Height properties. Also, don't use alClient for
the Align property. (Note that zooming-in via this approach isn't all
that efficient, so let me know if you run into performance issues.)
Cheers,
Analian wrote:
Quote
I tried putting the Image into a tScrollBox component which
can receive focus and has OnMouseWheel events published and tried putting my
code there but nothing happens (and I guess it shouldn't cause Image1->Align
is alClient and so the whole client area of the ScrollBox is occupied with
the Image).
 

{smallsort}

Re:TImage wheel handling

"Analian" < XXXX@XXXXX.COM >wrote in message
Quote
I've got a TImage component and I want to be able to
catch OnMouseWheelUp and OnMouseWheelDown events
TImage is not a windowed control. It cannot receive mouse wheel events at
all. You will have to handle the mouse wheel elsewhere, such as by placing
the TImage onto a windowed control like TPanel, and let the windowed control
handle the events. Or even let the form itself handle them instead.
Quote
The problem is that TImage is not a TWinControl descendant and
thus cannot receive focus. I tried putting the Image into a tScrollBox
component which can receive focus and has OnMouseWheel events
published and tried putting my code there but nothing happens (and I
guess it shouldn't cause Image1->Align is alClient and so the whole
client area of the ScrollBox is occupied with the Image).
I would think that the alignment would not matter. The TScrollBox is still
a windowed control being covered by a non-windowed control. The OS won't
even see the TImage at all, and still direct messages to the TScrollBox,
which it does see.
Quote
I also derived a new component from TImage and published the
wheel events but this also didn't work.
There are no wheel events in TImage to begin with, thus nothing to publish
from it.
Gambit
 

Re:TImage wheel handling

Quote
The handlers for these events are members of TForm. I confess to never
having used them but it seems logical for them to be there. Have you
had problems with them?
TForm's MouseWheel events work fine but if I handle things this away the
following problem arises. I've got a treeview in the form, which has lots of
items and thus a vertical scrollbar is being used. When the app runs the
focus is set to the treeview. I want to be able to click on the Image, for
example, and so it should receive focus and then I'll handle the events from
there. Since TImage is not a TWincontrol descendant, it cannot gain focus
and I can't do that. If I handle it through the Form's MouseWheel events, I
guess I must perform a check if the cursor is positioned on the Image and
then perform the zooming but what happens with the TreeView's wheel
handling? The first situation - I "suppress" the TreeView's wheel events
when cursor is on Image, the second - both zooming and scrolling happen at
the same time. Both are undesired, that's why I think I should use the
Form's events. If I'm wrong, please tell me what am I mistaking.
 

Re:TImage wheel handling

Quote
In addition to Andrue's comments, if you want to perform zooming with
the TImage, you'll need to set the Stretch property to true, and then
adjust the Width and Height properties. Also, don't use alClient for the
Align property. (Note that zooming-in via this approach isn't all that
efficient, so let me know if you run into performance issues.)
Thanks fot the advice but I want to display vector graphic so I'm going to
use stretching at all, cause all that I can
achieve there is distorting of the image, which is also undesired.
 

Re:TImage wheel handling

Quote
TImage is not a windowed control. It cannot receive mouse wheel events at
all. You will have to handle the mouse wheel elsewhere, such as by
placing
the TImage onto a windowed control like TPanel, and let the windowed
control
handle the events. Or even let the form itself handle them instead.
I think I shouldn't use the form's events (see my reply to Andrue's
messsage).
Quote
I would think that the alignment would not matter. The TScrollBox is
still
a windowed control being covered by a non-windowed control. The OS won't
even see the TImage at all, and still direct messages to the TScrollBox,
which it does see.
In fact the Image is already in a ScrollBox. I tried using the ScrollBox's
wheel events but nothing useful happens.
At first, I thought its because of the Image's Align property set to
alClient but you say it doesn't matter. I tried setting
the Align to alNone and leaving an uncovered area of the ScrollBox but even
when wheeling in this area, the events are not triggered. I also tried
making an enteriley new project and simply placed a ScrollBox on the form
without anything else
and again the events were not triggered. The only wheel events events which
are actually being triggered are the form's events.
So I still don't know what to do.
Quote
There are no wheel events in TImage to begin with, thus nothing to publish
from it.
Well, TImage is a TControl descendant and inherits its wheel events (am I
right?). So I simply derived a TMyImage
component and just published these inherited events. They even appeared in
the object inspector and I wrote handlers for
them which, of course, didn't do anything. So I don't quite understand what
do you mean.
 

Re:TImage wheel handling

"Analian" < XXXX@XXXXX.COM >wrote in message
Quote
When the app runs the focus is set to the treeview. I want to be
able to click on the Image, for example, and so it should receive
focus and then I'll handle the events from there. Since TImage is
not a TWincontrol descendant, it cannot gain focus
True, however the TScrollBox that the TImage sits on is a TWinControl
descendant, and as such will receive the focus when you click on the TImage.
Gambit