1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc. (http://www.novell.com)
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
34 namespace System.Windows.Forms {
35 public class TextBox : TextBoxBase {
36 #region Public Constructors
38 scrollbars = RichTextBoxScrollBars.None;
39 alignment = HorizontalAlignment.Left;
40 this.LostFocus +=new EventHandler(TextBox_LostFocus);
41 this.BackColor = ThemeEngine.Current.ColorWindow;
42 this.ForeColor = ThemeEngine.Current.ColorWindowText;
44 SetStyle (ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
45 SetStyle (ControlStyles.FixedHeight, true);
47 #endregion // Public Constructors
50 #region Private & Internal Methods
51 private void TextBox_LostFocus(object sender, EventArgs e) {
55 #endregion // Private & Internal Methods
57 #region Public Instance Properties
59 public bool AcceptsReturn {
61 return accepts_return;
65 if (value != accepts_return) {
66 accepts_return = value;
71 [DefaultValue(CharacterCasing.Normal)]
72 public CharacterCasing CharacterCasing {
74 return character_casing;
78 if (value != character_casing) {
79 character_casing = value;
86 public char PasswordChar {
92 if (value != password_char) {
93 password_char = value;
95 document.PasswordChar = value.ToString();
97 document.PasswordChar = "";
103 [DefaultValue(ScrollBars.None)]
105 public ScrollBars ScrollBars {
107 return (ScrollBars)scrollbars;
111 if (value != (ScrollBars)scrollbars) {
112 scrollbars = (RichTextBoxScrollBars)value;
113 base.CalculateScrollBars();
119 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
120 public override int SelectionLength {
122 return base.SelectionLength;
125 base.SelectionLength = value;
130 public override string Text {
140 [DefaultValue(HorizontalAlignment.Left)]
142 public HorizontalAlignment TextAlign {
148 if (value != alignment) {
151 // MS word-wraps if alignment isn't left
153 if (alignment != HorizontalAlignment.Left) {
154 document.Wrap = true;
156 document.Wrap = word_wrap;
160 for (int i = 1; i <= document.Lines; i++) {
161 document.GetLine(i).Alignment = value;
163 document.RecalculateDocument(CreateGraphics());
164 OnTextAlignChanged(EventArgs.Empty);
168 #endregion // Public Instance Properties
170 #region Protected Instance Methods
171 protected override CreateParams CreateParams {
173 return base.CreateParams;
177 protected override ImeMode DefaultImeMode {
179 return base.DefaultImeMode;
182 #endregion // Protected Instance Methods
184 #region Protected Instance Methods
185 protected override bool IsInputKey(Keys keyData) {
186 return base.IsInputKey (keyData);
189 protected override void OnGotFocus(EventArgs e) {
195 protected override void OnHandleCreated(EventArgs e) {
196 base.OnHandleCreated (e);
199 protected override void OnMouseUp(MouseEventArgs e) {
203 protected virtual void OnTextAlignChanged(EventArgs e) {
204 if (TextAlignChanged != null) {
205 TextAlignChanged(this, e);
209 protected override void WndProc(ref Message m) {
212 #endregion // Protected Instance Methods
215 public event EventHandler TextAlignChanged;