4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Novell, Inc.
26 // Jonathan Pobst (monkey@jpobst.com)
30 using System.Windows.Forms.VisualStyles;
32 namespace System.Windows.Forms
34 public sealed class TextBoxRenderer
36 #region Private Constructor
37 private TextBoxRenderer () { }
40 #region Public Static Methods
41 public static void DrawTextBox (Graphics g, Rectangle bounds, TextBoxState state)
43 DrawTextBox (g, bounds, String.Empty, null, Rectangle.Empty, TextFormatFlags.Default, state);
46 public static void DrawTextBox (Graphics g, Rectangle bounds, string textBoxText, Font font, TextBoxState state)
48 DrawTextBox (g, bounds, textBoxText, font, Rectangle.Empty, TextFormatFlags.Default, state);
51 public static void DrawTextBox (Graphics g, Rectangle bounds, string textBoxText, Font font, Rectangle textBounds, TextBoxState state)
53 DrawTextBox (g, bounds, textBoxText, font, textBounds, TextFormatFlags.Default, state);
56 public static void DrawTextBox (Graphics g, Rectangle bounds, string textBoxText, Font font, TextFormatFlags flags, TextBoxState state)
58 DrawTextBox (g, bounds, textBoxText, font, Rectangle.Empty, flags, state);
61 public static void DrawTextBox (Graphics g, Rectangle bounds, string textBoxText, Font font, Rectangle textBounds, TextFormatFlags flags, TextBoxState state)
64 throw new InvalidOperationException ();
66 VisualStyleRenderer vsr;
69 case TextBoxState.Assist:
70 vsr = new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Assist);
72 case TextBoxState.Disabled:
73 vsr = new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Disabled);
75 case TextBoxState.Hot:
76 vsr = new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Hot);
78 case TextBoxState.Normal:
79 case TextBoxState.Readonly:
81 vsr = new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Normal);
83 case TextBoxState.Selected:
84 vsr = new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Selected);
88 vsr.DrawBackground (g, bounds);
90 if (textBounds == Rectangle.Empty)
91 textBounds = new Rectangle (bounds.Left + 3, bounds.Top + 3, bounds.Width - 6, bounds.Height - 6);
93 if (textBoxText != String.Empty)
94 if (state == TextBoxState.Disabled)
95 TextRenderer.DrawText (g, textBoxText, font, textBounds, SystemColors.GrayText, flags);
97 TextRenderer.DrawText (g, textBoxText, font, textBounds, SystemColors.ControlText, flags);
101 #region Public Static Properties
102 public static bool IsSupported {
103 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }