Hola a tod@s
Tengo un panel que contiene tres
ListBox (CLAVE, INICIALES y DESCRIPCION), los cuales cargo desde una Tabla.
El problema consiste en que no soy capaz
de calcular el tamaño máximo del listbox DESCRIPCIÓN para que se vea TODO el texto que contiene. El código que utilizo es el siguiente:
Código Delphi
[-]
procedure TForm_GetListas.AjustarContenedor( var Panel:TPanel; ListBox:TListBox );
var
Panel_CONTENEDOR : TPanel;
begin
Panel_CONTENEDOR := (ListBox.Parent as TPanel);
ListBox_TEXTO.Width := ANCHO_TEXTO;
Panel_CONTENEDOR.Height := ((ListBox.Items.Count+1)*ListBox.ItemHeight);
Panel_CONTENEDOR.Width := ListBox_CLAVE.Width + ListBox_INIC.Width + ListBox_TEXTO.Width;
Bevel1.Width := Panel_CONTENEDOR.Left + Panel_CONTENEDOR.Width;
end;
procedure TForm_GetListas.MYSQL_PasarTipoToListas( Query:TZQuery;
strKey:string );
const
strTabla = 'datos_prueba';
var
strGrupo, strOrden : string;
Activo : integer;
Ancho : integer;
iOrden : integer;
Cadena : string;
begin
Activo := ITEM_INICIO;
Ancho := 0;
strGrupo := Copy( strKey, 1, 3 );
strOrden := Copy( strKey, 5, 3 );
with Query do begin
SQL.Clear;
SQL.Add( 'SELECT * ' );
SQL.Add( ' FROM ' + strTabla );
SQL.Add( ' WHERE grupo="' + strGrupo + '"' );
Open;
if IsEmpty then begin
end else begin
First;
while not eof do begin
iOrden := StrToInt( FieldByName('ORDEN').AsString ); Cadena := FieldByName('TEXTO' ).AsString;
Ancho := ListBox_TEXTO.Canvas.TextWidth( Cadena );
if( Ancho>ANCHO_TEXTO ) then ANCHO_TEXTO := Ancho;
ListBox_CLAVE.Items.Add( FieldByName('CLAVE').AsString );
ListBox_INIC.Items.Add( FieldByName('INICIALES').AsString );
ListBox_TEXTO.Items.Add( Trim(Cadena) );
if( FieldByName('CLAVE').AsString=strKey )
then Activo := ListBox_ORDEN.Items.Count-1;
Next;
end;
end;
Close;
end;
AjustarContenedor( Panel_TABLA, ListBox_CLAVE );
Panel_DESCRIBE_0.Caption := IntToStr( Ancho );
ActivarTablas( Activo );
end;
Gracias de antemano
Salvica