Changing the Border Style of a TextBox Control Without Raising Events
When changing the border style of a textbox control in .NET Framework 1.0 and 1.1, the original EDIT window is destroyed and a new window is created. This causes some issues, for example, changing the border style fires the control’s Enter event.
Instead of adjusting the window styles with P/Invoke on GetWindowLong, the RecreateHandle method is called which causes the Get procedure of the CreateParams property to be called. There, the style bits are adjusted according to the selected border style. The solution shown above is fully managed, nevertheless it causes wrong behavior, or in other words, “buggy” behavior. The class ExtendedTextBox does not have this problem and does not make use of unmanaged code too:
The code below can be used to check if changing the control’s border style causes a change of the control’s handle. If the handle is different from the handle obtained before changing the border style, the control was recreated:
There is a known issue for the textbox replacement described above. When changing the border stye to FixedSingle at designtime and then rebuilding the solution, the border will be shown incorrectly. This does not occur at runtime.