Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Creating a button like IE's Go

Hi,

I'm using Delphi 4 Pro.  I would like to create a button similar to the Go button in IE (the button that appears to the right of the address combo box).  The button needs to have these properties:

* Consist of both a glyph and text.
* There should be no border shown, except for when the mouse pointer is moved over the button.
* When the mouse pointer is moved over the button, the glyph should change from grey (default state) to colour (hot state).
* The button must *not* be part of a TToolbar.  I intend to place the button either directly on a form or on a TCoolBar.

I've tried using TButton, TBitBtn and TSpeedButton, however none seem to be able to do all of the above.

Can a button with the above properties be created in Delphi 4 Pro?  Do later versions of Delphi (such as Delphi 7 Pro) have any enhanced button components for doing the above?

Thanks in Advance,

Richard
0
Richard2000
Asked:
Richard2000
1 Solution
 
ILECommented:
i dont know for the button but u cen easily do that with other component
like the panel

put one panel on the form in this example panel2

set the bevelinear and bevelouter to false;

and put  this code in the  mosemove,mousedovn and  event



procedure TForm1.Panel2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  panel2.bevelinner:=bvraised;
end;

procedure TForm1.Panel2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  panel2.bevelinner:=bvlowered;
end;


{after that in the form mouse move do}
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
panel2.bevelinner:=bvnone;
end;


and you do what u wont arent you jut add code for one picture on the panel2 what u mey show hide or what u wont

and yes procedure TForm1.Panel2MouseDown
is the supstitution for buttonclick

you see just 3 easy commands :))

0
 
kretzschmarCommented:
just from scratch

unit HotSpeedButton;

interface

uses
  SysUtils, Classes, Controls, Buttons, graphics, messages;

type
  THotSpeedButton = class(TSpeedButton)
  private
    FHotBitmap : TBitMap;
    FOnMouseEnter : TNotifyEvent;
    FOnMouseLeave : TNotifyEvent;
    FNormalBitMap : TBitMap;
  protected
    Procedure CMMouseEnter(var Message : TMessage); Message CM_MouseEnter;
    Procedure CMMouseLeave(var Message : TMessage); Message CM_MouseLeave;
    Procedure SetHotBitMap(AValue : TBitMap);
    Procedure SetNormalBitMap(AValue : TBitMap);
  public
    Constructor Create(AOwner : TComponent); OverRide;
    Destructor Destroy; OverRide;
    { Public declarations }
  published
    property HotBitMap : TBitMap read FHotBitMap write SetHotBitMap;
    property NormalBitMap : TBitMap read FNormalBitMap write SetNormalBitMap;
    property onMouseEnter : TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    property onMouseLeave : TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
    { Published declarations }
  end;

procedure Register;

implementation

Constructor THotSpeedButton.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FHotBitmap := TBitMap.Create;
  FNormalBitMap := TBitMap.Create;
  Flat := True;
end;

Destructor THotSpeedButton.Destroy;
begin
  if assigned(FHotBitMap) then
    FHotBitMap.Free;
  if assigned(FNormalBitMap) then
    FNormalBitMap.Free;
  inherited Destroy;
end;

Procedure THotSpeedButton.CMMouseEnter(var Message : TMessage);
begin
  inherited;
  If Not (csDesigning in ComponentState) then
  begin
    If assigned(FHotBitmap) then
      Glyph.Assign(FHotBitMap);
    If assigned(FOnMouseEnter) then
      FOnMouseEnter(Self);
  end;
end;


Procedure THotSpeedButton.CMMouseLeave(var Message : TMessage);
begin
  inherited;
  If Not (csDesigning in ComponentState) then
  begin
    If assigned(FNormalBitMap) then
      Glyph.Assign(FNormalBitMap);
    If assigned(FOnMouseLeave) then
      FOnMouseLeave(Self);
  end;
end;

Procedure THotSpeedButton.SetHotBitMap(AValue : TBitMap);
begin
  FreeAndNil(FHotBitMap);
  if Assigned(AValue) then
  begin
    FHotBitMap := TBitMap.Create;
    FHotBitMap.Assign(AValue);
  end;
end;

Procedure THotSpeedButton.SetNormalBitMap(AValue : TBitMap);
begin
  FreeAndNil(FNormalBitMap);
  if Assigned(AValue) then
  begin
    FNormalBitMap := TBitMap.Create;
    FNormalBitMap.Assign(AValue);
  end;
  Glyph.Assign(AValue);
end;


procedure Register;
begin
  RegisterComponents('Samples', [tHotSpeedButton]);
end;

end.

meikl ;-)
0
 
Richard2000Author Commented:
Hi,

Thanks for the code.  I was just wondering if there was any way of creating such a button using the standard buttons components in the VCL that come with Delphi?

It is possible to create such a button as a button on a TToolBar in Delphi 4 Pro.  However, the TToolBar is intended for creating groups of buttons and I just need one button on its own that isn't part of a TToolBar.

Thanks in Advance,

Richard
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now