Solved

Glyph (easy)

Posted on 2004-03-24
8
902 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
[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
  • 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
Technology Partners: 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!

 

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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 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