Einzelnen Beitrag anzeigen

Benutzerbild von Nikolas
Nikolas

Registriert seit: 28. Jul 2003
1.528 Beiträge
 
Delphi 2005 Personal
 
#4

Re: Labels mit Stringgrid synchronisieren

  Alt 21. Sep 2005, 20:51
Meinst du sowas?

Label(0-4) werden jeweils unter der Zeile geparkt:

Delphi-Quellcode:
ablinks:=0;
for i := 0 to 4 do
 begin
  Tlabel(FindComponent('Label' + IntToStr(i))).Left := ablinks+sg.Left{+5};
  ablinks := ablinks + sg.ColWidths[i];
 end;
Kleines Update:

Delphi-Quellcode:
  

ablinks:=0;
for i := 0 to 4 do
 begin
  width:= form1.Canvas.TextWidth('Label'+inttostr(i));

  // linksbündig
  if rg.ItemIndex = 0 then
  delta := 0;
  
  // rechtsbündig:
  if rg.ItemIndex = 1 then
  begin
  if width<sg.ColWidths[i] then
   delta := sg.ColWidths[i]-width
  else
   delta := -1*(width-sg.ColWidths[i]);
  end;


  // zentriert:
  if rg.ItemIndex = 2 then
  begin
  if width<sg.ColWidths[i] then
   delta := round( (sg.ColWidths[i]-width) /2)
  else
   delta := round(-1* (width-sg.ColWidths[i]) /2);
   end;



  Tlabel(FindComponent('Label' + IntToStr(i))).Left := ablinks+sg.Left+5+delta;
  ablinks := ablinks + sg.ColWidths[i];
 end;
Erwarte das Beste und bereite dich auf das Schlimmste vor.
  Mit Zitat antworten Zitat