Best way to get an imaged button?

Everything else that doesn't fall into one of the other PB categories.
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Best way to get an imaged button?

Post by es_91 »

Hi, how can you make buttons that have images above the text or before the text?

There must be several ways out there, but I am looking for the easiest and still well way, maybe you can help me?

Also this could be a library entry for others who search for the same question.

How to do it?

:)
:mrgreen:
User avatar
TI-994A
Addict
Addict
Posts: 2791
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Best way to get an imaged button?

Post by TI-994A »

es_91 wrote:Hi, how can you make buttons that have images above the text or before the text?
Hi es_91. If I understand you correctly, this should do the trick:

Code: Select all

Enumeration 
  #MainWindow 
  #imgBtn
  #img
  #font
EndEnumeration

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, 0, 0, 200, 200, "ButtonImage", wFlags)
LoadImage(#img, "x:\xxx.bmp")   ;replace with your image file
LoadFont(#font, "Times New Roman", 14)
ResizeImage(#img, 150, 150)
StartDrawing(ImageOutput(#img))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(FontID(#font))
  FrontColor(RGB(255, 100, 100))
  ;BackColor(RGB(220, 220, 0))
  DrawText(40, 50, "Click Me")
StopDrawing()
ButtonImageGadget(#imgBtn, 25, 25, 150, 150, ImageID(#img))

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
To set a background colour for the text, remove the DrawingMode(#PB_2DDrawing_Transparent) line, and reinstate the BackColor() function.

Hope it's helpful. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2167
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Best way to get an imaged button?

Post by Andre »

There are several example codes for this task. One you can find here: http://www.purebasic.fr/english/viewtop ... age+button
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Best way to get an imaged button?

Post by Tenaja »

User avatar
TI-994A
Addict
Addict
Posts: 2791
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Best way to get an imaged button?

Post by TI-994A »

Tenaja wrote:Or this, using a built in command:
http://www.purebasic.com/documentation/ ... adget.html
Hi Tenaja. The additional code in my example was simply for adding text to the button, as requested. But basically, it was the built-in ButtonImageGadget(). :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: Best way to get an imaged button?

Post by es_91 »

Two different ways with great effect! Thanks! :)
:mrgreen:
Post Reply