Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Glyph (easy)

Posted on 2004-03-24
8
Medium Priority
?
908 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

670 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