Solved

Glyph (easy)

Posted on 2004-03-24
8
898 Views
Last Modified: 2013-12-02
How do you change bitbtn's glyph (lock) to on-off?
The glyph changes....
0
Comment
Question by:Bosanac
  • 5
  • 2
8 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10669689
do you mean?
BitBtn1.Glyph.LoadFromFile('name');
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10670217

 If you have a button, and two different glyphs,

 if on
 BitBtn1.Glyph.LoadFromFile('on.bmp')
 else
 BitBtn1.Glyph.LoadFromFile('off.bmp')


OR

var
 ONBMP, OFFBMP: TBitmap;

if On
 BitBtn1.Glyph.Assign(ONBMP)
else
 BitBtn1.Glyph.Assign(OFFBMP)

or if you have the images in a TImageList


if On
begin
 ImageList1.GetImage(0,ONBMP);
 BitBtn1.Glyph.Assign(ONBMP);
end
else
begin
 ImageList1.GetImage(1,OFFBMP)
 BitBtn1.Glyph.Assign(OFFBMP)
end;

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10670238
Im sorry thats assuning your using a TBitBnt or TSpeedButton

SHane
0
 

Author Comment

by:Bosanac
ID: 10687212
if "on" ?
is that boolean?
anyway I can not compile....
Getimage also fail's...
Mind showing me full source in case I am messing up?
I have 2 *.bmp's (off and on in my app. folder)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10687247
Im making you an example right now, post me an email address

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 25 total points
ID: 10687392
Note for this example you will have two glyphs (same size) in your ImageList
(ImageList height & width properties set to glyph height & width)

The Off image at index 0 and the OnImage at index 1 in the image list.

then

Create a BitBtn,

assign the Off bitmap to its Glyph property

set its caption to 'Off'

then place the folowing code in its OnClick event


procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 BitBtn1.Glyph:= nil; //clear glyph
 if BitBtn1.Caption = 'ON' then
 begin
  ImageList1.GetBitmap(0,BitBtn1.Glyph); //get Off image
  BitBtn1.Caption:= 'OFF'; //set caption to off
 end
 else
 begin
  ImageList1.GetBitmap(1,BitBtn1.Glyph);//get ON image
  BitBtn1.Caption:= 'ON';//set caption to on
 end;
end;
0
 
LVL 17

Expert Comment

by:mokule
ID: 10687635
unit BitBtnTest;

interface

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

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    st: boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  st := True;
  BitBtn1.Glyph.LoadFromFile('kask.bmp');
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  if st then
    begin
    if FileExists( 'info.bmp') then
      BitBtn1.Glyph.LoadFromFile('info.bmp')
    end
  else
    begin
    if FileExists( 'kask.bmp') then
      BitBtn1.Glyph.LoadFromFile('kask.bmp');
    end;
  st := not st;
end;

end.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10687678
yes mokule,  you could do it that way, but you would have to distribute the images with your application. If you have them in the imageList, they are already in the application.....

Another way, would be to have the images in the resource file, then load the bitbtn from the resource file....

Shane
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

19 Experts available now in Live!

Get 1:1 Help Now