Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #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
Poder: 21
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
  #2  
Antiguo 08-08-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
ixMike Va por buen camino
Hola.

Para saber el ancho de un ListBox yo utilizo esto:

Código Delphi [-]
Procedure TForm1.Button1Click(Sender: TObject);
var ancho, n: integer;
begin
ancho:=0;
for n:=0 to ListBox1.Items.Count-1 do
 if ListBox1.Canvas.TextWidth(ListBox1.Items[n])>ancho then
  ancho:=ListBox1.Canvas.TextWidth(ListBox1.Items[n]);
ListBox1.Width:=Ancho;
end;

Espero que te sea de ayuda.

Saludos
Responder Con Cita
  #3  
Antiguo 11-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
Poder: 21
salvica Va por buen camino
Cita:
Empezado por ixMike Ver Mensaje
Hola.

Para saber el ancho de un ListBox yo utilizo esto:

Código Delphi [-]Procedure TForm1.Button1Click(Sender: TObject);
var ancho, n: integer;
begin ancho:=0; for n:=0 to ListBox1.Items.Count-1 do if ListBox1.Canvas.TextWidth(ListBox1.Items[n])>ancho then ancho:=ListBox1.Canvas.TextWidth(ListBox1.Items[n]); ListBox1.Width:=Ancho; end;


Espero que te sea de ayuda.

Saludos
Me ha servido de muuuuuuucha ayuda
Gracias
Salvica
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
width con valor mínimo edusus Varios 1 02-04-2006 11:58:11
Auto - Width en DBLookupCombo juliopag1 Varios 0 12-12-2005 18:20:08
Problema con BitMap.Width fmtidona Gráficos 2 25-09-2005 02:34:07
Cargar Form1->Width desde el Registro de Windows JuanErasmo C++ Builder 3 20-09-2005 11:07:55
Ajuste del width de un objeto al maxlegth FNADALO OOP 9 26-05-2005 22:28:09


La franja horaria es GMT +2. Ahora son las 07:04:20.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi