Solved

Two Speedbuttons that are friends...

Posted on 2000-02-22
14
249 Views
Last Modified: 2010-04-04
I have two flat TSpeedButtons on a form. I would like the bevel around them to appear simultaneously; that is, when I move the mouse over one of them both buttons should indicate that.
Any advice?

>Daniel
0
Comment
Question by:Dippen
  • 5
  • 5
  • 2
  • +2
14 Comments
 

Expert Comment

by:manjushan
ID: 2545617
U can use the same function in both buttons onmouseover event.Or put both of them on a pannel and write an event of the pannel.Or u can use toolbar.Since speedbuttons dont have onmouseover events it will be better if u write your own component.
            Good luck.
                                               Manju.
0
 
LVL 2

Expert Comment

by:florisb
ID: 2545628
Hmmm, saw something in help, but that didn;t work:

speedbutton1.MouseInControl; //check help, doesn;t seem to work.

detect in form-mousemove event:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if speedbutton1.MouseInControl then
  begin
  speedbutton1.Enabled := true; //?
  speedbutton2.Enabled := true;
  end
else
  begin
  speedbutton1.Enabled := false;
  speedbutton2.Enabled := false;
  end;
end;

Floris.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2546065
This isn't ideal but it'll do what you want it to do.

For each of your speedbuttons, change the GroupIndex value to something unique (e.g. SpeedButton1.GroupIndex = 1, SpeedButton2.GroupIndex = 2...). Make sure that the AllowAllUp property is set to TRUE for all of them.

Then in your MouseMove event for SpeedButton1, add the following:

  SpeedButton1.Down := TRUE;
  SpeedButton2.Down := TRUE;

Then in the MouseMove event for the FORM (or whatever your buttons are on top of), add the following:

  SpeedButton1.Down := FALSE;
  SpeedButton2.Down := FALSE;

Like I said, it isn;t ideal but when you move over Speedbutton1, BOTH buttons will have their bevels displayed

The Neil
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:Dippen
ID: 2549338
The bevel I'm referring to is the one that's displayed to indicate that if I click with the mouse, the button will be activated. It only applies to flat buttons. Therefore, the Down property is of no interest.
I think the right way is to send a Windows message in some way to the button that is not affected by the mouse cursor. Unfortunately, I'm not an expert of Windows messaging.
0
 

Author Comment

by:Dippen
ID: 2549344
Adjusted points to 100
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2549571
Dippen,

You CAN use a WIndow message system but my solution will raise the bevel around both buttons. Stop trying to make things overly complex

The Neil
0
 

Author Comment

by:Dippen
ID: 2551693
I'm not making things overly complex, you're just not right about this. When I change the Down property to Down the button also changes color and gets a little bit lighter. That's not what I'm looking for. I'm very well aware of what I'm looking for!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2553486
hi dippen,

try this descandend component
(not tested in all cases)

unit FriendSpeedButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons;

type
  TFriendSpeedButton = class(TSpeedButton)
  private
    FFriendButton : TFriendSpeedButton;

    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  published
    { Published declarations }
    property FriendButton : TFriendSpeedButton read FFriendButton write FFriendButton;
  end;

procedure Register;

implementation

procedure TFriendSpeedButton.CMMouseEnter(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then
  begin
    If M.WParam <> 1 then
    begin
      M.WParam := 1;
      FFriendButton.CMMouseEnter(M);
    end;
  end;
end;

procedure TFriendSpeedButton.CMMouseLeave(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then
  begin
    If M.WParam <> 1 then
    begin
      M.WParam := 1;
      FFriendButton.CMMouseLeave(M);
    end;
  end;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TFriendSpeedButton]);
end;

end.

meikl
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 2553562
hi again,

a bit modification, to allow more than two friends:

unit FriendSpeedButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons;

type
  TFriendSpeedButton = class(TSpeedButton)
  private
    FFriendButton : TFriendSpeedButton;

    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  published
    { Published declarations }
    property FriendButton : TFriendSpeedButton read FFriendButton write FFriendButton;
  end;

procedure Register;

implementation

procedure TFriendSpeedButton.CMMouseEnter(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then      //is there a friend
  begin
    If (M.WParam = 0) then             //am i the first then
      M.WParam := Integer(self);       //remember me
    if (M.WParam <> Integer(FFriendButton)) then  //if not my Friend the first then
      FFriendButton.CMMouseEnter(M);              //tell him the event
  end;
end;

procedure TFriendSpeedButton.CMMouseLeave(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then     //is there a friend
  begin
    If (M.WParam = 0) then            //am i the first then
      M.WParam := Integer(self);      //remember me
    if (M.WParam <> Integer(FFriendButton)) then //if not my Friend the first then
      FFriendButton.CMMouseLeave(M);             //tell him the event
  end;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TFriendSpeedButton]);
end;

end.

connect the friends with the friendbutton-property

two ways are possible:
circular chain : f1-f2-f3-f1
open chain : f1-f2-f3 (f3 has no friend)

the effect is a bit different

meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2554910
appendix,

there is one bug:
if you at designmode delete a friend, which is assigned on another friend as friend, you will get an accessviolation on the other friend by selecting the friend-property.

the component must be expanded by a component-notification (one additional procedure)

if it from interest, i will post the changes here

meikl
0
 

Author Comment

by:Dippen
ID: 2554945
Perfect! Exactly the behavior I was looking for!
Thanks a bunch, meikl!!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2555013
well, dippen,
glad to helped you :-)
will post tomorow the solve
of the destroyed friend
problem at designmode
good luck again
meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2556918
hi again,

here the change

unit FriendSpeedButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons;

type
  TFriendSpeedButton = class(TSpeedButton)
  private
    FFriendButton : TFriendSpeedButton;

    { Private declarations }
  protected
    { Protected declarations }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    { Public declarations }
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  published
    { Published declarations }
    property FriendButton : TFriendSpeedButton read FFriendButton write FFriendButton;
  end;

procedure Register;

implementation

procedure TFriendSpeedButton.CMMouseEnter(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then      //is there a friend
  begin
    If (M.WParam = 0) then             //am i the first then
      M.WParam := Integer(self);       //remember me
    if (M.WParam <> Integer(FFriendButton)) then  //if not my Friend the first then
      FFriendButton.CMMouseEnter(M);              //tell him the event
  end;
end;

procedure TFriendSpeedButton.CMMouseLeave(var Message: TMessage);
var M : TMessage;
begin
  M := Message;
  inherited;
  if assigned(FFriendButton) then     //is there a friend
  begin
    If (M.WParam = 0) then            //am i the first then
      M.WParam := Integer(self);      //remember me
    if (M.WParam <> Integer(FFriendButton)) then //if not my Friend the first then
      FFriendButton.CMMouseLeave(M);             //tell him the event
  end;
end;

procedure TFriendSpeedButton.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited  Notification(AComponent, Operation);
  If Operation = opRemove then          //will be removed something then
    If AComponent = FFriendButton then  //is it my friend then
       FFriendButton := Nil;            //my friend is gone
end;

procedure Register;
begin
  RegisterComponents('Samples', [TFriendSpeedButton]);
end;

end.

meikl
0
 

Author Comment

by:Dippen
ID: 2559985
Note taken! Thanks again!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question