Link to home
Start Free TrialLog in
Avatar of the_modder
the_modderFlag for United States of America

asked on

Change image on mouseover

Hi. I'd like to have an application in which I have 6 images. The first image should be a menu that is full unselected. The second should be the menu full selected. The third should be depressed (when I am holding the mouse button down). And the 4th should be a new image. The 5th should be when the new image is being displayed, but when I am holding my mouse over it. And the 6th should be when I am clicking it. For example, I have a mute button. When the mouse is not over it, it should be unselected. When the mouse is over it it should be selected. The third should be when I am holding the mouse button down. And the 4th should be when I have already clicked on it and it changed to another image (muted). The 5th should be when I am holding my mouse over the muted image (and it being highlighted), and the 6th should be when I am clicking on the mute button and it become unmuted.

But also this code has to have the other parts of the menu be clickable, but not to change to a different image after being clicked. Oh, it also needs to be FAST.

Here is some code. https://www.experts-exchange.com/questions/21061934/Delete-part-of-image.html#11745650

Thanks,
David Burban
Avatar of the_modder
the_modder
Flag of United States of America image

ASKER

bump? Points increased to 175!
Avatar of Darth_helge
Darth_helge

well, i won't be doing your whole task, but you have to implement the mouseEnter and mouseLeave events on an image component (or a button component or whatever you want to use)

here is code for an image component with those events. Just open this is in delphi and choose component-->install component


unit InfoImg;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  ExtCtrls;
type
  TInfoImage = class(TImage)
  private
    FOnMouseLeave: TNotifyEvent;
    FOnMouseEnter: TNotifyEvent;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  protected
  public
  published
    property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
    property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Info Components', [TInfoImage]);
end;

procedure TInfoImage.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;

procedure TInfoImage.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;

end.
The thing is that I have a menu of like 13 items. I want to do the 6 image thing to only 2 of them. The rectangles in the link that I gave pull parts of the selected image onto the deselected image over where my mouse is. That's what I want, except with 6 images (just two buttons like this, the rest should be like in the link, but with mousehold).
maybe I didn't read your whole question. But your question title is "Change image on mouseover"....
Yeh, I can't really summarize it in a few words :|
Look at Delphi Help for TSpeedButton. I think you'll find it's what you want.
Use the TToolbar. Add six TImageList to your form.  One set each for every stage you mentioned.
For those buttons uneffeced, load the same image into the image list.
Set the first two sets to Images and HotImages property of TToolbar.  This takes care of mouse over image change event. For onclick and when selected, change the Images and HotImages property to point to the correct sets of image list.  Refresh the toolbar if need to, depends on what you are doing.
The thing is that I don't want to cut out every image and then do that. If you look at the link, it has code that just needs some improvement on how many iages it has. Cutting out a lot of images would be a waste of time because it can be done in code.
the_modder
do you have much of an idea what my code (in your other question) does?
can you show some code that you have made, to try and do what you say you want?
or do I have to code the whole thing again?

did you try a new TRectShow Record?
can you show what you added to it?

TRectShow = record // record type to keep Show and Rect info
    Show: Boolean;
    Muted: Boolean; // maybe add a muted boolean
    ImgRect: TRect;
    end;

and where whould you test for this Muted boolean value to get it to show a muted picture?

and wouldn't your sixth image be the same as your second image?
goes from muted (image 4)  BACK TO unmuted (image 2)
Slick812, by now I think it should be clear that the_modder wants full solutions written for him rather than ideas about how to solve the problem himself. This may be because he is a total novice to programming, just lazy, genuinely confused or has decided that EE is a great place to get cheap consulting. Given my experience with the previous thread and his responses here, I have to wonder what he'd be satisified with short of a complete implementation (from his very nebulous specs).
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
....Cutting out a lot of images would be a waste of time because it can be done in code....

how many button images can a program have?
If it would make you feel better. use only two TImageList and change the ImageIndex property on the fly.  six TImageList make beter image management because the images are all in the same sequence.
With HotImage and Images property, combined with mouse events, TToolButton has all the thing you need to implement this.  And if TToolbar gets in the way of your background, put only one button on each toolbar and make the toolbar the same size as the button.
Why go to such extreme coding ? Unless you have cut the code from somewhere and keep insisting to make it work.