Right-aligned Edit Control

Implementing an edit control which contains right-alligned text requires deriving a new component from TEdit and overriding the CreateParams method.  With the introduction of Windows98/2000 (NT5), the ES_MULTILINE restriction was lifted when adding the ES_RIGHT style.  If you are developing for Windows 95/NT4 platforms, also flag the ES_MULTILINE style, but be aware, you may have to add carriage return trapping.

KEYWORDS: ES_RIGHT, CreateParams
 

 

//-----------------------------------------------------------------------------
// REditCode.h ===========================================
//---------------------------------------------------------------------------
#ifndef REditCodeH
#define REditCodeH
//---------------------------------------------------------------------------
#include <vcl\SysUtils.hpp>
#include <vcl\Controls.hpp>
#include <vcl\Classes.hpp>
#include <vcl\Forms.hpp>
#include <vcl\StdCtrls.hpp>
//---------------------------------------------------------------------------
#if (__BORLANDC__ < 0x0530)
//---------------------------------------------------------------------------
// BCB 1.0
//---------------------------------------------------------------------------
  #define PACKAGE
  #define DYNAMIC

#endif
//---------------------------------------------------------------------------

class PACKAGE TREdit : public TEdit
{
private:
protected:
public:
   __fastcall TREdit(TComponent* Owner);
   virtual void __fastcall CreateParams(TCreateParams &Params);
__published:
};
//---------------------------------------------------------------------------
#endif
 

 


 
 
 

//---------------------------------------------------------------------------
// REditCode.cpp ==========================================
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "REditCode.h"
//---------------------------------------------------------------------------
#if (__BORLANDC__ < 0x0530)
//---------------------------------------------------------------------------
// BCB 1.0
//---------------------------------------------------------------------------
static inline TREdit *ValidCtrCheck()
{
   return new TREdit(NULL);
}
//---------------------------------------------------------------------------
#else
//---------------------------------------------------------------------------
// BCB 3.0/4.0
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TREdit *)
{
   new TREdit(NULL);
}
//---------------------------------------------------------------------------
#endif

//---------------------------------------------------------------------------
__fastcall TREdit::TREdit(TComponent* Owner)
: TEdit(Owner)
{
}

//---------------------------------------------------------------------------
void __fastcall TREdit::CreateParams(TCreateParams &Params)
{
    TEdit::CreateParams(Params);
    Params.Style = Params.Style | ES_RIGHT;// ES_MULTILINE;
}

//---------------------------------------------------------------------------
namespace Reditcode
{
   void __fastcall PACKAGE Register()
    {
        TComponentClass classes[1] = {__classid(TREdit)};
        RegisterComponents("Samples", classes, 0);
    }
}
 

 


 
 

You are welcome to cut and paste the code above and save it into two separate files, then install on the component palette.    The idea though, is to learn the methods... so use this as an example, then go out and create an even better version!