Skip to main content

TdxBadges.Add Method

Creates a new UI badge and adds it to the collection.

Declaration

function Add: TdxBadge;

Returns

Type Description
TdxBadge

The created UI badge adorner.

Remarks

Call the Add function to create a new badge and add it as the last collection item accessible through the Items property. To insert a badge at any position in the collection, call the Insert function.

Code Examples

Display UI Badges for All Hamburger Menu Groups

You can use badges to mark or highlight individual UI elements in your application.

The following code example creates UI badges for all groups in a Navigation Bar control and configures badge appearance and position settings:

var
  I: Integer;
  ABadge: TdxBadge;
  AElementPath: TdxAdornerTargetElementPath;
begin
  dxUIAdornerManager1.BeginUpdate;  // Initiates the following batch change
  try
    for I := 0 to dxNavBar1.Groups.Count - 1 do  // Iterates through all navigation bar groups
    begin
      ABadge := dxUIAdornerManager1.Badges.Add;  // Creates a badge for the corresponding group
      ABadge.Text := IntToStr(I);  // Uses the group index as the badge caption
      // Associate the created badge with the corresponding navigation bar group
      ABadge.TargetElementClass := TdxAdornerTargetElementPath;
      AElementPath := ABadge.TargetElement as TdxAdornerTargetElementPath;
      AElementPath.Path := dxNavBar1.Name + '.' + dxNavBar1.Groups[I].Name;
    end;
    dxUIAdornerManager1.Badges.Active := True;  // Displays created badges
  finally
    dxUIAdornerManager1.EndUpdate;  // Calls EndUpdate regardless of the batch operation's success
  end;
end;

VCL Editors Library: UI Badges that Mark Navigation Bar Groups

Create and Position a UI Element Badge

The following code example creates a badge and moves it up by 5 pixels and right by 50 pixels:

var
  ABadge: TdxBadge;
  AElementControl: TdxAdornerTargetElementControl;
begin
  dxUIAdornerManager1.BeginUpdate;  // Initiates the following batch change
  try
    ABadge := dxUIAdornerManager1.Badges.Add;  // Creates a badge
    ABadge.Text := 'Prints the Report';  // Specifies the badge's caption
    ABadge.Offset.X := 50;  // Moves the badge right by 50 pixels from the base position
    ABadge.Offset.Y := -5;  // Moves the badge up by 5 pixels from the base position
    // Customize the appearance of the created badge
    ABadge.Background.Color := clLime;
    ABadge.Font.Style := [fsBold];
    ABadge.Font.Color := clBlue;
    // Associate the created badge with a TcxButton
    ABadge.TargetElementClass := TdxAdornerTargetElementControl;
    AElementControl := ABadge.TargetElement as TdxAdornerTargetElementControl;
    AElementControl.Control := cxButton1;  // Specifies the target button
    dxUIAdornerManager1.Badges.Active := True;  // Displays the created badge
  finally
    dxUIAdornerManager1.EndUpdate;  // Calls EndUpdate regardless of the batch operation's success
  end;
end;

VCL Editors Library: A Custom Badge for a Button

UI Badge Deletion

Call the Clear procedure to delete all UI badges. To delete individual badges, call the Remove procedure.

See Also