Ver Mensaje Individual
  #1  
Antiguo 11-12-2004
megaman_x megaman_x is offline
Registrado
 
Registrado: dic 2004
Posts: 6
Reputación: 0
megaman_x Va por buen camino
Exclamation Tcombobox solo lectura

bueno antes ke nada si ya existe algo asi, por favor hagan referencia.

Escribi este componente basado en otros posts, es un combobox con la propiedad SoloLEctura que cuando su valor es TRUE, el color se cambia a clBtnFace y style a csSimple, ademas hereda los metodos keyUp y KeyDown para evitar escritura.

Solo falta que con el clic derecho del raton no se pueda cortar o pegar, dejando la opcion de copiar disponible. Creo que tampoco me funciona Ctrl + C pero eso es mas facil.

Una ayudadita por favor


Código:
 unit uCrusserComboboxEx;
 
 interface
 
 uses
   Windows, Messages, SysUtils, Classes, Controls, StdCtrls,graphics;
 
 type
   TCrusserComboBoxEx = class(TComboBox)
   private
 	{ Private declarations }
 	bReadOnly: Boolean;
 	procedure fLectura(valor: Boolean);
   protected
 	procedure KeyDown(var Key: Word; Shift: TShiftState);override;
 	procedure KeyPress(var Key: Char);override;
   public
 	property SoloLectura:boolean read bReadOnly write fLectura;
   published
 	{ Published declarations }
   end;
 
 procedure Register;
 
 implementation
 
 procedure Register;
 begin
   RegisterComponents('Misc', [TCrusserComboBoxEx]);
 end;
 
 procedure TCrusserComboBoxEx.fLectura(Valor: Boolean);
 begin
   bReadOnly := Valor;
   if bReadOnly then begin
 	Color := clBtnFace;
 	Style := csSimple;
   end else begin
 	Color := clWindow;
 	Style := csDropDown;
   end;
 
 end;
 
 procedure TCrusserComboBoxEx.KeyDown(var Key: Word; Shift: TShiftState);
 begin
   inherited;
   if bReadOnly then
 	if (key = VK_DELETE)
 	   or (Key = VK_UP)
 	   or (Key = VK_DOWN)
 		 then key := word(#0); // this allows the user to tab
 end;
 
 procedure TCrusserComboBoxEx.KeyPress(var Key: Char);
 begin
   inherited;
   if bReadOnly then
 	key := #0;
 end;
 
 end.
Salud!!
Responder Con Cita