The control is recreated since you are changing the Window Style.
Const ES_LEFT As Int32 = &H0
Const ES_RIGHT As Int32 = &H2
I can't think of a method to overcome your problem though, since the TextBox
loses and gains focus when it is recreated.

Signature
Mick Doherty
http://dotnetrix.co.uk/nothing.html
> Hi All,
>
[quoted text clipped - 23 lines]
> thanks in advance,
> -vj
Herfried K. Wagner [MVP] - 26 Dec 2004 22:23 GMT
"Mick Doherty"
<EXCHANGE#WITH@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> schrieb:
> The control is recreated since you are changing the Window Style.
>
> Const ES_LEFT As Int32 = &H0
> Const ES_RIGHT As Int32 = &H2
ACK. Changing these styles requires a recreation of the native (Win32)
textbox window.

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/
Mick Doherty - 26 Dec 2004 22:47 GMT
I just had a thought about checking in the OnLayout Method and it does seem
to work in there.
\\\
Protected Overrides Sub OnLayout(ByVal levent As LayoutEventArgs)
MyBase.OnLayout(levent)
If IsNumeric(Me.Text) AndAlso Not Me.Focused _
AndAlso Me.TextAlign <> HorizontalAlignment.Right Then
Me.TextAlign = HorizontalAlignment.Right
ElseIf Me.TextAlign <> HorizontalAlignment.Left Then
Me.TextAlign = HorizontalAlignment.Left
End If
End Sub
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
Me.PerformLayout()
MyBase.OnTextChanged(e)
End Sub
Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
Me.PerformLayout()
MyBase.OnGotFocus(e)
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
Me.PerformLayout()
MyBase.OnLostFocus(e)
End Sub
///

Signature
Mick Doherty
http://dotnetrix.co.uk/nothing.html
> The control is recreated since you are changing the Window Style.
>
[quoted text clipped - 33 lines]
>> thanks in advance,
>> -vj
Vijay Phulwadhawa - 26 Dec 2004 23:38 GMT
Thanks a lot Mick.
The idea of using OnLayout is new to me, I will give it a look.
Though I fixed the bug by checking if the control has focus or not in
OnCreateControl, which seems to break the infinite loop.
if ((true == m_IsNumeric) && (0 != this.TextLength) && (true ==
this.Focused))
{
//the default alignment code goes here
}
thanks again all for the feedbacks.
-vj
> I just had a thought about checking in the OnLayout Method and it does seem
> to work in there.
[quoted text clipped - 71 lines]
> >> thanks in advance,
> >> -vj