Solved

Glyph (easy)

Posted on 2004-03-24
8
904 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 103
Convert a string into a TDateTime 5 80
FMX and jaudiotracker playing memory stream 29 108
Remove all child-forms from a parent-panel 16 17
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…
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…
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…

752 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