Article View: borland.public.cppbuilder.nativeapi
Article #12278Re: Alignment.
From: JD
Date: Sun, 14 Dec 2003 12:11
Date: Sun, 14 Dec 2003 12:11
97 lines
3740 bytes
3740 bytes
"Safari" <Safari@alloymail.com> wrote:
> I want to have a TEdit with taCenter alignment,
You could use the SetWindowLong() function or subclass the
TEdit and dynamically allocate the object:
class TCEdit : public TEdit
{
public:
__fastcall TCEdit( TComponent* Owner ) : TEdit( Owner )
{
}
void __fastcall CreateParams( TCreateParams& Params )
{
TEdit::CreateParams( Params );
Params.Style |= ES_CENTER;
}
};
TCEdit* CenteredEdit = new TCEdit( this );
Note : you can also use the same code to make a right-aligned
edit by replacing ES_CENTER with ES_RIGHT (and changing the
name of course).
OR derive your own component and install it to a package. Click Component | New Component and make the code look like this:
//---- header
//-------------------------------------------------------------
#ifndef CEditH
#define CEditH
//-------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
//-------------------------------------------------------------
class PACKAGE TCEdit : public TEdit
{
private:
protected:
public:
__fastcall TCEdit(TComponent* Owner);
virtual void __fastcall CreateParams( TCreateParams& Params );
__published:
};
//-------------------------------------------------------------
#endif
//-- cpp
//-------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CEdit.h"
#pragma package(smart_init)
//-------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TCEdit *)
{
new TCEdit(NULL);
}
//-------------------------------------------------------------
__fastcall TCEdit::TCEdit(TComponent* Owner) : TEdit(Owner)
{
}
//-------------------------------------------------------------
void __fastcall TCEdit::CreateParams( TCreateParams& Params )
{
TEdit::CreateParams( Params );
Params.Style = Params.Style | ES_CENTER; // ES_MULTILINE;
}
//-------------------------------------------------------------
namespace Cedit
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TCEdit)};
RegisterComponents("Samples", classes, 0);
}
}
//-------------------------------------------------------------
Then save the files and click Component | Install Component
and select a new package that you will provide the name for.
Also note that not all versions of Windows support ES_CENTER
and ES_RIGHT for single-line edit controls. The alternative is
to use a TMemo instead, sized to a single line, and disable the
Enter key and strip out carriage returns when pasting text.
~ JD
Technical Details
Message-ID:
<3fdc6187$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fdc4d0c@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5ff3c30c3de5a5e,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-12-14 05:22:35 PST From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: Alignment. Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 172.174.203.47 References: <3fdc4d0c@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <3fdc6187$1@newsgroups.borland.com> Date: 14 Dec 2003 05:11:35 -0700 X-Trace: newsgroups.borland.com 1071407495 207.105.83.66 (14 Dec 2003 05:11:35 -0700) Lines: 98 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail