ABCButtons unit in PascalABC.NET

From Wikibooks, open books for an open world
Jump to navigation Jump to search

ABCButtons - is a PascalABC.NET unit intended for simple GUI application's creation.

Controls

[edit | edit source]
  1. ButtonABC - a button

ButtonABC class

[edit | edit source]

Inheritance chain: ButtonABC > ABCObjects.UIElementABC > ABCObjects.RectangleABC > ABCObjects.BoundedObjectABC > ABCObjects.ObjectABC.

Constructor

[edit | edit source]
Name Way to memorize Type Description
x x integer An X-coordinate of the button location
y y integer An Y-coordinate of the button location
w width integer A width of the button
h height integer A height of the button
txt text string A text on the button
cl color GraphABC.Color A color of the button

Fields

[edit | edit source]
Name Type Description
OnClick procedure A procedure called on the button click

Properties

[edit | edit source]

Inherited from base classes.

Examples

[edit | edit source]

Create a new button with Click me! text on it:

new ButtonABC(0, 0, 200, 50, 'Click me!', clRed);

Examples

[edit | edit source]
uses ABCButtons, GraphABC;

begin
  var button := new ButtonABC(0, 0, 200, 50, 'Press me to change my color', clRed);
  button.OnClick := procedure ->
  begin
    button.Color := clRandom();
    button.FontColor := RGB(255 - button.Color.R, 255 - button.Color.G, 255 - button.Color.B);
  end;
end.
uses GraphABC, ABCObjects, ABCButtons;

const
  ButtonSize = 50;
  BoxSize = 100;
  MoveValue = 5;

begin
  Window().Caption := 'Press buttons to translate the figure';
  
  var left := new ButtonABC(0, 0, ButtonSize, ButtonSize, 'left', clRed);
  var right := new ButtonABC(ButtonSize, 0, ButtonSize, ButtonSize, 'right', clYellow);
  var up := new ButtonABC(ButtonSize * 2, 0, ButtonSize, ButtonSize, 'up', clGreen);
  var down := new ButtonABC(ButtonSize * 3, 0, ButtonSize, ButtonSize, 'down', clBlue);
  
  var rectangle := new RectangleABC(Window().Width div 2 - BoxSize div 2,
                                    Window().Height div 2 - BoxSize div 2,
                                    BoxSize, BoxSize, clGray);
  
  left.OnClick := procedure() -> rectangle.MoveOn(-MoveValue, 0);
  right.OnClick := procedure() -> rectangle.MoveOn(MoveValue, 0);
  up.OnClick := procedure() -> rectangle.MoveOn(0, -MoveValue);
  down.OnClick := procedure() -> rectangle.MoveOn(0, MoveValue);
end.