Solved

Two Speedbuttons that are friends...

Posted on 2000-02-22
14
243 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now