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
Solved

Glyph (easy)

Posted on 2004-03-24
8
901 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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