Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I have two buttons behave as one

Posted on 1998-06-06
1
Medium Priority
?
153 Views
Last Modified: 2010-04-06
I am using the buttons from Magikit.  So I am using 2 buttons with a picture between them.  This in fact looks like it is one button. It looks very nice except for the fact that this buttons also have the property of changing appearance when the cursor is on top of them. So if I am on top of the first button, I would like the second's button' appearance to change as well since they are meant to look like one button. How can I make sure they are in sync that way ?
0
Comment
Question by:skylinka
1 Comment
 
LVL 3

Accepted Solution

by:
Matvey earned 400 total points
ID: 1351228
Hi

Sorry, don't know what is Magikit, so if it's something cool let me know...

The code below works for TSpeedButton, but I'm sure it's adjustable for your buttons. Your buttons might also have events for mouseenter and mouseleave, but here I create them by myself so the code is a bit long.

PS if you want to see even more cool button behavior, post your email and I'll send you a component I worte...

unit Unit1;

interface

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

type
  TNewSpeedButton = class(TspeedButton)
  private
    FOnMouseEnter: TNotifyEvent;
    FOnMouseLeave: TNotifyEvent;
  Protected
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  Published
    Property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    Property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  end;

  TForm2 = class(TForm)
    SpeedButton1: TSpeedButton;
    procedure FormCreate(Sender: TObject);

    procedure btn1MouseEnter(Sender: TObject);
    procedure btn1MouseLeave(Sender: TObject);
    procedure btn2MouseEnter(Sender: TObject);
    procedure btn2MouseLeave(Sender: TObject);
  private
    { Private declarations }
  public
    btn1, btn2 : TNewSpeedButton;
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TNewSpeedButton.CMMouseEnter(var Message: TMessage);
Begin
  Inherited;
  if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;

procedure TNewSpeedButton.CMMouseLeave(var Message: TMessage);
Begin
  Inherited;
  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;

procedure TForm2.btn1MouseEnter(Sender: TObject);
Begin
  Btn2.OnMouseEnter := nil;
 btn2.Perform(CM_MOUSEENTER, 0, 0);
  Btn2.OnMouseEnter := btn2MouseEnter;
end;

procedure TForm2.btn1MouseLeave(Sender: TObject);
Begin
  Btn2.OnMouseLeave := nil;
 btn2.Perform(CM_MOUSELEAVE, 0, 0);
  Btn2.OnMouseLeave := btn2MouseLeave;
end;

procedure TForm2.btn2MouseEnter(Sender: TObject);
Begin
  Btn1.OnMouseEnter := nil;
 btn1.Perform(CM_MOUSEENTER, 0, 0);
  Btn1.OnMouseEnter := btn1MouseEnter;
end;

procedure TForm2.btn2MouseLeave(Sender: TObject);
Begin
  Btn1.OnMouseLeave := nil;
 btn1.Perform(CM_MOUSELEAVE, 0, 0);
  Btn1.OnMouseLeave := btn1MouseLeave;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  Btn1 := TNewSpeedButton.Create(Self);
  Btn2 := TNewSpeedButton.Create(Self);
  Btn1.Parent := Self;
  Btn2.Parent := Self;

  btn1.SetBounds(20, 20, 20, 20);
  btn2.SetBounds(40, 20, 20, 20);
  btn1.Caption := 'A';
  btn2.Caption := 'B';
  btn1.Flat := True;
  btn2.Flat := True;

  Btn1.OnMouseEnter := btn1MouseEnter;
  Btn2.OnMouseEnter := btn2MouseEnter;
  Btn1.OnMouseLeave := btn1MouseLeave;
  Btn2.OnMouseLeave := btn2MouseLeave;
end;

end.


(A code of a simple Delphi unit...)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

877 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