Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #6  
Antiguo 21-02-2012
elGuerrero elGuerrero is offline
Miembro
NULL
 
Registrado: ene 2012
Posts: 10
Poder: 0
elGuerrero Va por buen camino
Lightbulb Solución con WMPaint

La solución anterior me ocasionó problemas en la apariencia del componente pues borraba el contenido de él, no actualizaba cuando cambiaba la MaxLength y otros detalles.
Se me ocurrió hacerlo a través de WMPaint, que se ejecuta al redibujar el control, así que recargue los procedimientos

Código:
  TEditor = class(TEdit)
    procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  protected
    procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
    procedure SetAutoSize(Value: Boolean); override;
    procedure DoSetMaxLength(Value: Integer); virtual;
  end;
Luego en la sección de implementationredefiní el procedimiento

Código:
procedure TEditor.WMPaint(var Msg: TWMPaint);
var
  sText: String;
  MCanvas: TControlCanvas;
begin
  if (AutoSize) and (MaxLength > 0) then
    Begin
    MCanvas := TControlCanvas.Create;
    try
      MCanvas.Control   := Self;
      MCanvas.Font      := Self.Font;
      sText:= DupeString('X', MaxLength+2);
      Self.Width:= MCanvas.TextWidth(sText);
    finally
      MCanvas.Free;
    end; //try
    End;
  Inherited;
end;
Para forzarlo a redibujar el componente, utilicé RePaint en los mismos procedimientos:

Código:
procedure TEditor.SetAutoSize(Value: Boolean);
begin
  inherited;
  Repaint;
end;

procedure TEditor.DoSetMaxLength(Value: Integer);
begin
  inherited;
  Repaint;
end;

procedure TEditor.CMFontChanged(var Message: TMessage);
begin
  inherited;
  Repaint;
end;
Y ahora si, ya está funcionando como deseaba.

Esta solución la terminé consultando varios códigos fuente, sin embargo, tengo duda en cuanto a que si tengo bugs en el código o errores de diseño ¿Uds. qué creen?
Les agradezco de antemano sus respuestas.
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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
Modificar DBGrid desde TEdit jhonalone Conexión con bases de datos 6 21-02-2011 18:47:26
Delphi-For-PHP: Modificar el valor de un tEdit maro PHP 4 29-09-2007 20:25:21
Ajustar el width de un TListBox salvica OOP 2 11-08-2007 20:04:01
modificar o crear componente TEdit chivix OOP 3 08-03-2007 18:50:50
Pasar al siguiente Edit al llegar a maxlength Durbed Varios 4 08-11-2005 20:31:36


La franja horaria es GMT +2. Ahora son las 13:07:16.


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