Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2004

Tip: Looking for answers? Try searching our database.

Is it a bug?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vijay Phulwadhawa - 25 Dec 2004 23:43 GMT
Hi All,

I am writing a custom textbox control derived from the original textbox
control.

In one of my requirement, I have to right align the controls text when its
numeric , and it should be left aligned when the control has the focus.
This has been accomplished successfully, but recently a bug was pointed out
that the control text is left aligned (the default) at form load , so I
added the code to align text in the OnControlCreate sub.

Now the real problem arises, when the form is run, it give an exception
window handle cannot be created, on debugging I found that the control is
"re created" on every TextAlign property change ! The code infinetly jumps
between GotFocus and OnControlCreate . (Note that i have code to change the
textalign in GotFocus also).

Is this a bug, or there a specific reason the control needs to be recreated
for a property change ?

Can anybody suggest a alternate way to fix the bug.

thanks in advance,
-vj
Mick Doherty - 26 Dec 2004 22:15 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.