• Viernes 29 de Marzo de 2024, 16:10

Autor Tema:   Lista De Fuentes En Un Listbox O Combobox  (Leído 3628 veces)

_Viktor

  • Miembro MUY activo
  • ***
  • Mensajes: 271
    • Ver Perfil
    • http://AyudaCBuilder.foros.st
Lista De Fuentes En Un Listbox O Combobox
« en: Sábado 6 de Diciembre de 2003, 03:06 »
0
Hola, primero hagan un formulario con la sgte. forma:




Luego en el evento OnCreate del form lo siguiente:

Código: Text
  1.  
  2. //---------------------------------------------------------------------------
  3. void __fastcall TForm1::FormCreate(TObject *Sender)
  4. {
  5.    
  6.     for(int i = 0; i < Screen->Fonts->Count; i++)
  7.     {
  8.         ListBox1->Items->Add(Screen->Fonts->Strings[i]);
  9.         ComboBox1->Items->Add(Screen->Fonts->Strings[i]);
  10.     }
  11.  
  12.     int F = ComboBox1->Items->IndexOf("Times New Roman " );
  13.     if( F ) // If the font exists, select it
  14.         ComboBox1->ItemIndex = F;
  15. }
  16. //---------------------------------------------------------------------------
  17.  
  18.  
  19.  

luego:

Código: Text
  1.  
  2. //---------------------------------------------------------------------------
  3. void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,
  4.       TRect &Rect, TOwnerDrawState State)
  5. {
  6.     if( State.Contains(odSelected) )
  7.         ListBox1->Canvas->Brush->Color = clHighlight;
  8.     else
  9.         ListBox1->Canvas->Brush->Color = clWhite;
  10.  
  11.  
  12.     ListBox1->Canvas->FillRect(Rect);
  13.  
  14.     ListBox1->Canvas->Pen->Color = clWhite;
  15.     ListBox1->Canvas->Font->Name = ListBox1->Items->Strings[Index];
  16.     ListBox1->Canvas->Font->Size = 12;
  17.     ListBox1->Canvas->TextOut(Rect.Left, Rect.Top, ListBox1->Items->Strings[Index]);
  18. }
  19. //---------------------------------------------------------------------------
  20. void __fastcall TForm1::ComboBox1DrawItem(TWinControl *Control, int Index,
  21.       TRect &Rect, TOwnerDrawState State)
  22. {
  23.     if( State.Contains(odSelected) )
  24.         ComboBox1->Canvas->Brush->Color = clHighlight;
  25.     else
  26.         ComboBox1->Canvas->Brush->Color = clWhite;
  27.  
  28.     ComboBox1->Canvas->FillRect(Rect);
  29.  
  30.     ComboBox1->Canvas->Font->Name = ComboBox1->Items->Strings[Index];
  31.     ComboBox1->Canvas->Font->Size = 12;
  32.     ComboBox1->Canvas->TextOut(Rect.Left, Rect.Top-2, ComboBox1->Items->Strings[Index]);
  33. }
  34. //---------------------------------------------------------------------------
  35.  
  36.  
  37.  

para que al final el resultado se vea de esta forma:



Espero les sirva.

Saludos!

[EDIT: no modifique nada, fue un error  :hola: ]
_Viktor _Yañez_
"Ser inteligente no es ser mas, solo equivocarse menos y no usar visual basic"

http]

Vatoicc

  • Miembro activo
  • **
  • Mensajes: 65
    • Ver Perfil
Re: Lista De Fuentes En Un Listbox O Combobox
« Respuesta #1 en: Sábado 13 de Mayo de 2006, 00:43 »
0
Muy buen tip, nada mas se te olvido agregar que para el ComboBox hay que modificar una propiedad

   ComboBox1->Style = csOwnerDrawVariable;

No lo e probado en el ListBox, pero es un buen tip para darle presentacion a un programa
La paranoia es una vision mas sutil de la vida

ronal120

  • Nuevo Miembro
  • *
  • Mensajes: 4
    • Ver Perfil
Re: Lista De Fuentes En Un Listbox O Combobox
« Respuesta #2 en: Lunes 12 de Mayo de 2008, 03:07 »
0
muy interesante