2 // System.Windows.Forms.TextBox
5 // stubbed out by Jackson Harper (jackson@latitudegeo.com)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
9 // (C) 2002 Ximian, Inc
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.ComponentModel
;
35 namespace System
.Windows
.Forms
{
38 // Represents a Windows text box control.
41 public class TextBox
: TextBoxBase
{
43 HorizontalAlignment textAlign
;
45 CharacterCasing characterCasing
;
47 ScrollBars scrollbars
;
52 textAlign
= HorizontalAlignment
.Left
;
54 characterCasing
= CharacterCasing
.Normal
;
55 passwordChar
= (char)0;
56 scrollbars
= ScrollBars
.None
;
59 public bool AcceptsReturn
{
60 get { return acceptsReturn; }
62 if ( acceptsReturn
!= value ) {
63 int oldStyle
= acceptsReturn
? (int)EditControlStyles
.ES_WANTRETURN
: 0;
64 acceptsReturn
= value;
65 int newStyle
= acceptsReturn
? (int)EditControlStyles
.ES_WANTRETURN
: 0;
66 if ( IsHandleCreated
)
67 Win32
.UpdateWindowStyle ( Handle
, oldStyle
, newStyle
);
72 public CharacterCasing CharacterCasing
{
73 get { return characterCasing; }
75 if ( !Enum
.IsDefined ( typeof(CharacterCasing
), value ) )
76 throw new InvalidEnumArgumentException( "CharacterCasing",
78 typeof(CharacterCasing
));
80 if ( characterCasing
!= value ) {
81 int oldStyle
= CaseStyle
;
82 characterCasing
= value;
83 if ( IsHandleCreated
)
84 Win32
.UpdateWindowStyle ( Handle
, oldStyle
, CaseStyle
);
89 public char PasswordChar
{
90 get { return passwordChar; }
93 if ( IsHandleCreated
)
94 Win32
.SendMessage ( Handle
, (int) EditControlMessages
.EM_SETPASSWORDCHAR
, passwordChar
, 0 );
98 public ScrollBars ScrollBars
{
99 get { return scrollbars; }
101 if ( !Enum
.IsDefined ( typeof(ScrollBars
), value ) )
102 throw new InvalidEnumArgumentException( "ScrollBars",
106 if ( scrollbars
!= value ) {
107 int oldStyle
= ScrollBarStyle
;
109 if ( IsHandleCreated
)
110 Win32
.UpdateWindowStyle ( Handle
, oldStyle
, ScrollBarStyle
);
115 public HorizontalAlignment TextAlign
{
116 get { return textAlign; }
118 if ( !Enum
.IsDefined ( typeof(HorizontalAlignment
), value ) )
119 throw new InvalidEnumArgumentException( "TextAlign",
121 typeof(HorizontalAlignment
));
123 if ( textAlign
!= value ) {
126 OnTextAlignChanged ( EventArgs
.Empty
);
131 public event EventHandler TextAlignChanged
;
134 protected override CreateParams CreateParams
{
136 CreateParams createParams
= base.CreateParams
;
138 createParams
.ClassName
= "EDIT";
139 createParams
.Style
|= (int) ( WindowStyles
.WS_CHILD
) | TextAlignStyle
| ScrollBarStyle
| CaseStyle
;
141 createParams
.Style
|= (int)EditControlStyles
.ES_WANTRETURN
;
148 protected override ImeMode DefaultImeMode
{
149 get { return ImeMode.Inherit; }
152 // --- Protected Members
154 protected override bool IsInputKey(Keys keyData
)
157 return base.IsInputKey(keyData
);
160 protected override void OnHandleCreated(EventArgs e
)
163 base.OnHandleCreated(e
);
164 if ( PasswordChar
!= 0 )
165 Win32
.SendMessage ( Handle
, (int) EditControlMessages
.EM_SETPASSWORDCHAR
, PasswordChar
, 0 );
168 protected override void OnMouseUp(MouseEventArgs mevent
)
171 base.OnMouseUp(mevent
);
175 protected override void OnGotFocus(EventArgs e
) {
180 protected virtual void OnTextAlignChanged(EventArgs e
)
182 if ( TextAlignChanged
!= null )
183 TextAlignChanged ( this, EventArgs
.Empty
);
186 protected override void WndProc(ref Message m
)
192 private int TextAlignStyle
196 switch ( TextAlign
) {
197 case HorizontalAlignment
.Left
:
198 style
= (int) EditControlStyles
.ES_LEFT
;
200 case HorizontalAlignment
.Center
:
201 style
= (int) EditControlStyles
.ES_CENTER
;
203 case HorizontalAlignment
.Right
:
204 style
= (int) EditControlStyles
.ES_RIGHT
;
211 private int ScrollBarStyle
215 switch ( this.ScrollBars
) {
216 case ScrollBars
.Vertical
:
217 style
= (int) WindowStyles
.WS_VSCROLL
;
219 case ScrollBars
.Horizontal
:
221 style
= (int) WindowStyles
.WS_HSCROLL
;
223 case ScrollBars
.Both
:
224 style
= (int) WindowStyles
.WS_VSCROLL
;
226 style
= (int) WindowStyles
.WS_HSCROLL
;
234 private int CaseStyle
238 switch ( this.CharacterCasing
) {
239 case CharacterCasing
.Lower
:
240 style
= (int) EditControlStyles
.ES_LOWERCASE
;
242 case CharacterCasing
.Upper
:
243 style
= (int) EditControlStyles
.ES_UPPERCASE
;