Solved

How can I have two buttons behave as one

Posted on 1998-06-06
1
143 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 100 total points
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

11 Experts available now in Live!

Get 1:1 Help Now