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 ComboBoxRenderer
36 #region Private Constructor
37 private ComboBoxRenderer () { }
40 #region Public Static Methods
41 public static void DrawDropDownButton (Graphics g, Rectangle bounds, ComboBoxState state)
44 throw new InvalidOperationException ();
46 GetComboRenderer (state).DrawBackground (g, bounds);
49 public static void DrawTextBox (Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, TextFormatFlags flags, ComboBoxState state)
52 throw new InvalidOperationException ();
54 GetTextBoxRenderer (state).DrawBackground (g, bounds);
56 if (textBounds == Rectangle.Empty)
57 textBounds = new Rectangle (bounds.Left + 3, bounds.Top, bounds.Width - 4, bounds.Height);
59 if (comboBoxText != String.Empty)
60 if (state == ComboBoxState.Disabled)
61 TextRenderer.DrawText (g, comboBoxText, font, textBounds, SystemColors.GrayText, flags);
63 TextRenderer.DrawText (g, comboBoxText, font, textBounds, SystemColors.ControlText, flags);
66 public static void DrawTextBox (Graphics g, Rectangle bounds, ComboBoxState state)
68 DrawTextBox (g, bounds, String.Empty, null, Rectangle.Empty, TextFormatFlags.VerticalCenter, state);
71 public static void DrawTextBox (Graphics g, Rectangle bounds, string comboBoxText, Font font, ComboBoxState state)
73 DrawTextBox (g, bounds, comboBoxText, font, Rectangle.Empty, TextFormatFlags.VerticalCenter, state);
76 public static void DrawTextBox (Graphics g, Rectangle bounds, string comboBoxText, Font font, Rectangle textBounds, ComboBoxState state)
78 DrawTextBox (g, bounds, comboBoxText, font, textBounds, TextFormatFlags.Default, state);
81 public static void DrawTextBox (Graphics g, Rectangle bounds, string comboBoxText, Font font, TextFormatFlags flags, ComboBoxState state)
83 DrawTextBox (g, bounds, comboBoxText, font, Rectangle.Empty, flags |= TextFormatFlags.VerticalCenter, state);
87 #region Private Static Methods
88 private static VisualStyleRenderer GetComboRenderer (ComboBoxState state)
91 case ComboBoxState.Disabled:
92 return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Disabled);
93 case ComboBoxState.Hot:
94 return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Hot);
95 case ComboBoxState.Normal:
97 return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Normal);
98 case ComboBoxState.Pressed:
99 return new VisualStyleRenderer (VisualStyleElement.ComboBox.DropDownButton.Pressed);
103 private static VisualStyleRenderer GetTextBoxRenderer (ComboBoxState state)
106 case ComboBoxState.Disabled:
107 return new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Disabled);
108 case ComboBoxState.Hot:
109 return new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Hot);
110 case ComboBoxState.Normal:
111 case ComboBoxState.Pressed:
113 return new VisualStyleRenderer (VisualStyleElement.TextBox.TextEdit.Normal);
118 #region Public Static Properties
119 public static bool IsSupported {
120 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }