AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

KI Code verbessern, ListBox mit Label

Ein Thema von bernhard_LA · begonnen am 28. Jul 2025 · letzter Beitrag vom 28. Jul 2025
 
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.149 Beiträge
 
Delphi 11 Alexandria
 
#1

KI Code verbessern, ListBox mit Label

  Alt Gestern, 10:47
Ich habe mir über KI eine Funktion zum Erstellen einer ListBox mit einer Überschrift zusammengestellt:

Delphi-Quellcode:

function CreateCheckListBox(AParent: TWinControl; Top, Left, W, H: Integer;
  Titel: String): TListBox;
var
  ListBoxLabel: TLabel;
  aListBox: TListBox;
begin
  // Create the TListBox component
  aListBox := TListBox.Create(AParent);
  try
    aListBox.Parent := AParent;
    // Position and size the list box
    aListBox.SetBounds(Left, Top, W, H);

    // Create a label for the list box
    ListBoxLabel := TLabel.Create(AParent);
    ListBoxLabel.Parent := AParent;
    // Position label relative to the list box
    ListBoxLabel.SetBounds(Left, Top - 25, W, 20); // Positioned 25 pixels above the list box
    ListBoxLabel.Caption := Titel;

    // Return the created list box
    Result := aListBox;
  except
    aListBox.Free;
    raise;
  end;
end;

Meine Listboxen erzeuge ich dann zur Luufzeit auf meinem Form mit dieser Zeile Code:

Delphi-Quellcode:
  

// Create the fifth list box
  lst_Elements := CreateCheckListBox(PanelListBoxes, StartTop,
    CurrentLeft, ListBoxWidth, ListBoxHeight, 'Show Elements');
  inc(CurrentLeft, ListBoxWidth + SpacingX);


Funktioniert soweit ganz gut, über einige weitere Iterationen habe ich dann diese Funktion erhalten um meine 6 List Boxen auf meinem Form auch bei einer Größenanpassung zu "Resizen" :




Delphi-Quellcode:
procedure MyForm.ResizeListBoxes;
const
  SpacingX = 20; // Space between list boxes horizontally
  StartTop = 30; // Starting position from the top of the container
  StartLeft = 10; // Starting position from the left of the container
var
  i: Integer;
  CurrentLeft: Integer;
  ListBoxWidth, ListBoxHeight: Integer;
  ListBoxes: array[0..5] of TWinControl; // Array for both TListBox and TCheckListBox
begin
  // Initialize the list boxes array
  ListBoxes[0] := dlist; // ...
  ListBoxes[1] := SelectedIndices; // ...
  ListBoxes[2] := lst_List; // TListBox
  ListBoxes[3] := lst_List2; // TListBox
  ListBoxes[4] := lst_Elements; // TListBox
  ListBoxes[5] := lst_List3; // TListBox

  // Initialize starting left position
  CurrentLeft := StartLeft;

  // Calculate dimensions
  ListBoxWidth := Round((PanelListBoxes.ClientWidth - ((Length(ListBoxes) - 1) * SpacingX)) /
    Length(ListBoxes)); // Divide width evenly among list boxes
  ListBoxHeight := PanelListBoxes.ClientHeight - 2 * StartTop;

  // Adjust all list boxes dynamically
  for i := Low(ListBoxes) to High(ListBoxes) do
  begin
    if Assigned(ListBoxes[i]) then
    begin
      // Set bounds for the list box or checklist box
      ListBoxes[i].SetBounds(CurrentLeft, StartTop, ListBoxWidth, ListBoxHeight);
      // Move to the next position
      Inc(CurrentLeft, ListBoxWidth + SpacingX);
    end;
  end;
end;
Wo meine KI an Ihre aktuellen Grenzen Stößt: Label und Listbox bei einer Resize-Änderung anzupassen. Was ist denn hier der einfachste Weg?
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:07 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz