Solved

Two Speedbuttons that are friends...

Posted on 2000-02-22
14
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

615 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