Solved

How can I have two buttons behave as one

Posted on 1998-06-06
1
149 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
[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
1 Comment
 
LVL 3

Accepted Solution

by:
Matvey earned 100 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

Industry Leaders: 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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

632 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