What Is A DelphiVCL.BitBtn And Why Would I Use It?
By Muhammad Azizul Hakim December 24, 2021
DelphiVCL.BitBtn is a push button control that can include a bitmap on its face. It’s an alternative to the regular button control which can’t directly use graphics on it.
Bitmap buttons exhibit the same behavior as button controls. We use them to initiate actions from forms and dialog boxes.
Bitmap buttons implement properties that specify the bitmap images, along with their appearance and placement on the button. You can choose from predefined bitmap buttons styles or use your own customized bitmap for the button. Although the button can be associated with only one bitmap, the bitmap (glyph property) can be subdivided into four equal-sized portions, which are displayed based on the state of the button: Up, down, disabled, and clicked.
The Kind property of BitBtn provides commonly used buttons, such as OK, Cancel, Help, and so on. These predefined button types have corresponding graphical images and default behaviors, so you can easily add them to your application with little or no coding necessary.
The recommended way to implement the response of other button kinds to user clicks is to assign action from an action list as the value of the Action property. By setting the Action property, you make the button a client of the action, and the action handles updating the button’s properties and responding when the user clicks the button.
If you are not using the built-in response to a specific kind of button or action to respond when the user clicks the button, then you can specify the button’s response by writing an OnClick event handler.
See the responses in our Windows command prompt:
To see the result, let’s run the complete script:
By Muhammad Azizul Hakim December 24, 2021
DelphiVCL.BitBtn is a push button control that can include a bitmap on its face. It’s an alternative to the regular button control which can’t directly use graphics on it.
Bitmap buttons exhibit the same behavior as button controls. We use them to initiate actions from forms and dialog boxes.
Bitmap buttons implement properties that specify the bitmap images, along with their appearance and placement on the button. You can choose from predefined bitmap buttons styles or use your own customized bitmap for the button. Although the button can be associated with only one bitmap, the bitmap (glyph property) can be subdivided into four equal-sized portions, which are displayed based on the state of the button: Up, down, disabled, and clicked.
The Kind property of BitBtn provides commonly used buttons, such as OK, Cancel, Help, and so on. These predefined button types have corresponding graphical images and default behaviors, so you can easily add them to your application with little or no coding necessary.
The recommended way to implement the response of other button kinds to user clicks is to assign action from an action list as the value of the Action property. By setting the Action property, you make the button a client of the action, and the action handles updating the button’s properties and responding when the user clicks the button.
If you are not using the built-in response to a specific kind of button or action to respond when the user clicks the button, then you can specify the button’s response by writing an OnClick event handler.
What properties and methods are available on the DelphiVCL.BitBtn?
Let’s browse all the properties and methods of the DelphiVCL.BitBtn using dir() command:
Python:
import DelphiVCL
dir(DelphiVCL.BitBtn)
Is there an example of using the DelphiVCL.BitBtn?
Here is the working example of the implementation of BitBtn:
Python:
#Button OK
btnOK = BitBtn(pgOne, Kind = 'OK')
btnOK.SetProps(Parent=pgOne,Caption = 'OK', Name = 'OK')
btnOK.SetBounds(65,50,60,30)
#Button Cancel
btnCancel = BitBtn(pgOne, Kind = 'Cancel')
btnCancel.SetProps(Parent=pgOne,Caption = 'Cancel', Name = 'Cancel')
btnCancel.SetBounds(145,50,60,30)
#Button Help
btnHelp = BitBtn(pgOne, Kind = 'Help')
btnHelp.SetProps(Parent=pgOne,Caption = 'Help',Name = 'Help')
btnHelp.SetBounds(65,100,60,30)
#Button Insert
btnInsert = BitBtn(pgOne, Kind = 'Insert')
btnInsert.SetProps(Parent=pgOne,Caption = 'Insert',Name = 'Insert')
btnInsert.SetBounds(145,100,60,30)
Python:
from DelphiVCL import *
# Create a Class to build a basic Form
class MainForm(Form):
def __init__(self, Owner):
self.Caption = "Introduction to VCL Components"
self.Name = "BaseForm"
self.SetBounds(10, 10, 500, 450)
# Create a Main Panel component
pnlMain = CreateComponent('TPanel',Owner)
pnlMain.SetProps(Parent=self, Caption="",align = "alClient", Name = "MainPanel")
# Page control creation
pgConMain = PageControl(pnlMain)
pgConMain.Name = "MyPageControl"
pgConMain.Parent = pnlMain
pgConMain.Align = "alClient"
# Tabsheet one
pgOne = TabSheet(pnlMain)
pgOne.PageControl = pgConMain
pgOne.Caption = "Tab 1"
#Button OK
btnOK = BitBtn(pgOne, Kind = 'OK')
btnOK.SetProps(Parent=pgOne,Caption = 'OK', Name = 'OK')
btnOK.SetBounds(65,50,60,30)
#Button Cancel
btnCancel = BitBtn(pgOne, Kind = 'Cancel')
btnCancel.SetProps(Parent=pgOne,Caption = 'Cancel', Name = 'Cancel')
btnCancel.SetBounds(145,50,60,30)
#Button Help
btnHelp = BitBtn(pgOne, Kind = 'Help')
btnHelp.SetProps(Parent=pgOne,Caption = 'Help',Name = 'Help')
btnHelp.SetBounds(65,100,60,30)
#Button Insert
btnInsert = BitBtn(pgOne, Kind = 'Insert')
btnInsert.SetProps(Parent=pgOne,Caption = 'Insert',Name = 'Insert')
btnInsert.SetBounds(145,100,60,30)
# Initialize your application
def main():
Application.Initialize()
Application.Title = "MyDelphiApp"
f = MainForm(Application)
f.Show()
FreeConsole()
Application.Run()
Application.Destroy()
main()