Board index » cppbuilder » right aligned TEDit

right aligned TEDit


2006-12-21 04:42:52 AM
cppbuilder36
Hi!
First of all: I want a TEdit or simmilar, right aligned, that shows the
right part of a text if it doesn't fit on the viewable size.
I know this is a recurring issue, but I have already implemented a
TEditdescendant overriding createParams using es_right, but it shows the
"left" part of the text, and TMemo right aligned does the same.
If it's not clear, an example:
Imagine a TEdit which can only show 4 characters, and the text is
iwannaright. With the examples I found, I can make it right aligned but
it shows "iwan" and I want it to show "ight".
Any ideas? or should I put the text manually calculating its width?
 
 

Re:right aligned TEDit

=?ISO-8859-1?Q?Dar=EDo_Alejandro_Guzik?= < XXXX@XXXXX.COM >wrote:
Quote

I want a TEdit or simmilar, right aligned,
So you know, only multi-line controls support alignment on all
operating systems. I would suggest that you use a TMemo and
set it's properties to make it indistinguishable from a TEdit.
Quote
that shows the right part of a text if it doesn't fit on the
viewable size.
You have 2 choices here. Change it's Width or set it's SelStart
to zero in the OnEnter event. If the OnEnter event fires too
soon, use PostMessage to post a custom message that will get
processed after the default behavior has finished executing.
~ JD
 

Re:right aligned TEDit

JD wrote:
Quote
=?ISO-8859-1?Q?Dar=EDo_Alejandro_Guzik?= < XXXX@XXXXX.COM >wrote:
>I want a TEdit or simmilar, right aligned,

So you know, only multi-line controls support alignment on all
operating systems. I would suggest that you use a TMemo and
set it's properties to make it indistinguishable from a TEdit.
There is no problem since it won't be editable. I just want to show some
data, so multiline or not I will make it show in 1 line
Quote

>that shows the right part of a text if it doesn't fit on the
>viewable size.

You have 2 choices here. Change it's Width or set it's SelStart
to zero in the OnEnter event. If the OnEnter event fires too
soon, use PostMessage to post a custom message that will get
processed after the default behavior has finished executing.

I can't change the width since it is fixed due to the form design the
client needs. onEnter cannot be used since the control will be readonly
and I need it to show the right part always.
I'm trying with TMemo but no matter if I set worwrapping true or false,
it wraps the text when it passes beyond the viewable width
Quote
~ JD

 

{smallsort}

Re:right aligned TEDit

=?ISO-8859-1?Q?Dar=EDo_Alejandro_Guzik?= < XXXX@XXXXX.COM >wrote:
Quote

>[...] I would suggest that you use a TMemo
As it happens, I didn't know TMemo as well as I thought that
I did. When I tested it, even though I set WantReturns and
WordWrap to false, TMemo still formatted it's Lines based
on where they would wrap based on it's Width *and* this was
reflected in it's Text property as well (which is just a
getter anyway so that's not *that* surprising).
The result was a double vertical bar (||) where the lines were
breaking so I had to switch to a TEdit.
Quote
I just want to show some data, so multiline or not I will
make it show in 1 line that shows the right part of a text
if it doesn't fit on the viewable size.
You'll have to manage that yourself at runtime by subclassing
the TEdit's WindowProc method (you can also subclass the
control and either override it's WndProc *or* use a message
map):
// Add to the header
private:
TWndMethod OldWndProc;
void __fastcall NewWndProc( TMessage &Message );
public:
__fastcall ~TForm1();
// add to the unit
//-------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
OldWndProc = Edit1->WindowProc;
Edit1->WindowProc = NewWndProc;
}
//-------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
Edit1->WindowProc = OldWndProc;
}
//-------------------------------------------------------------
void __fastcall TForm1::NewWndProc( TMessage &Message )
{
OldWndProc( Message );
if( Message.Msg == WM_PAINT )
{
TCanvas *pCanvas = new TCanvas;
pCanvas->Handle = ::GetDC( Edit1->Handle );
TRect R = Edit1->ClientRect;
pCanvas->FillRect( R );
::DrawText( pCanvas->Handle, Edit1->Text.c_str(), -1, &R, DT_SINGLELINE | DT_RIGHT );
::ReleaseDC( Edit1->Handle, pCanvas->Handle );
pCanvas->Handle = NULL;
delete pCanvas;
}
}
//-------------------------------------------------------------
~ JD