Ver Mensaje Individual
  #1  
Antiguo 07-08-2007
Avatar de salvica
salvica salvica is offline
Miembro
 
Registrado: mar 2004
Ubicación: Albacete (España) ... En un lugar de la Mancha ...
Posts: 304
Reputación: 23
salvica Va por buen camino
Ajustar el width de un TListBox

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 [-]
{
  ajustar el TPanel contenedor de los TListBox
  ANCHO_TEXTO se declara como integer y global en el Form
}
procedure TForm_GetListas.AjustarContenedor( var Panel:TPanel; ListBox:TListBox );
var
  Panel_CONTENEDOR : TPanel;
begin
{ altura del contenedor }
  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;


{
  rellenar los TListBox desde la tabla
  ANCHO_TEXTO se declara como integer y global en el Form
}
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
     { viene preparada de la función que la llama }
       SQL.Clear;
       SQL.Add( 'SELECT * ' );
       SQL.Add( '  FROM ' + strTabla );
       SQL.Add( ' WHERE grupo="' + strGrupo + '"' );
     { abrir la tabla activa }
       Open;
       if IsEmpty then begin
          //Memo.Text := 'MYSQL - No encontrada la clave ['+strKey+']';
       end else begin
          First;
          while not eof do begin
                iOrden   := StrToInt( FieldByName('ORDEN').AsString ); // div 10;
                Cadena   := FieldByName('TEXTO' ).AsString;
              { 
                ¿aquí compruebo el acho que debe tener?
              }
                Ancho    := ListBox_TEXTO.Canvas.TextWidth( Cadena );
                if( Ancho>ANCHO_TEXTO ) then ANCHO_TEXTO := Ancho;
              { 
                rellenar los TListBox
              }
                ListBox_CLAVE.Items.Add( FieldByName('CLAVE').AsString );
                ListBox_INIC.Items.Add( FieldByName('INICIALES').AsString );
                ListBox_TEXTO.Items.Add( Trim(Cadena) );
              { 
                si es la clave, activar el TListBox
              }
                if( FieldByName('CLAVE').AsString=strKey )
                    then Activo := ListBox_ORDEN.Items.Count-1;
                Next;
          end;
       end;
     { cerrar la tabla activa }
       Close;
  end; { del with Query do }
{ dar tamaño al contenedor de Listas }
  AjustarContenedor( Panel_TABLA, ListBox_CLAVE );
  Panel_DESCRIBE_0.Caption := IntToStr( Ancho );
{ activar las listas }
  ActivarTablas( Activo );
end;

Gracias de antemano
Salvica
Responder Con Cita