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)
31 using System
.Windows
.Forms
.VisualStyles
;
33 namespace System
.Windows
.Forms
35 public sealed class ComboBoxRenderer
37 #region Private Constructor
38 private ComboBoxRenderer () { }
41 #region Public Static Methods
42 public static void DrawDropDownButton (Graphics g
, Rectangle bounds
, ComboBoxState state
)
45 throw new InvalidOperationException ();
47 GetComboRenderer (state
).DrawBackground (g
, bounds
);
50 public static void DrawTextBox (Graphics g
, Rectangle bounds
, string comboBoxText
, Font font
, Rectangle textBounds
, TextFormatFlags flags
, ComboBoxState state
)
53 throw new InvalidOperationException ();
55 GetTextBoxRenderer (state
).DrawBackground (g
, bounds
);
57 if (textBounds
== Rectangle
.Empty
)
58 textBounds
= new Rectangle (bounds
.Left
+ 3, bounds
.Top
, bounds
.Width
- 4, bounds
.Height
);
60 if (comboBoxText
!= String
.Empty
)
61 if (state
== ComboBoxState
.Disabled
)
62 TextRenderer
.DrawText (g
, comboBoxText
, font
, textBounds
, SystemColors
.GrayText
, flags
);
64 TextRenderer
.DrawText (g
, comboBoxText
, font
, textBounds
, SystemColors
.ControlText
, flags
);
67 public static void DrawTextBox (Graphics g
, Rectangle bounds
, ComboBoxState state
)
69 DrawTextBox (g
, bounds
, String
.Empty
, null, Rectangle
.Empty
, TextFormatFlags
.VerticalCenter
, state
);
72 public static void DrawTextBox (Graphics g
, Rectangle bounds
, string comboBoxText
, Font font
, ComboBoxState state
)
74 DrawTextBox (g
, bounds
, comboBoxText
, font
, Rectangle
.Empty
, TextFormatFlags
.VerticalCenter
, state
);
77 public static void DrawTextBox (Graphics g
, Rectangle bounds
, string comboBoxText
, Font font
, Rectangle textBounds
, ComboBoxState state
)
79 DrawTextBox (g
, bounds
, comboBoxText
, font
, textBounds
, TextFormatFlags
.Default
, state
);
82 public static void DrawTextBox (Graphics g
, Rectangle bounds
, string comboBoxText
, Font font
, TextFormatFlags flags
, ComboBoxState state
)
84 DrawTextBox (g
, bounds
, comboBoxText
, font
, Rectangle
.Empty
, flags
|= TextFormatFlags
.VerticalCenter
, state
);
88 #region Private Static Methods
89 private static VisualStyleRenderer
GetComboRenderer (ComboBoxState state
)
92 case ComboBoxState
.Disabled
:
93 return new VisualStyleRenderer (VisualStyleElement
.ComboBox
.DropDownButton
.Disabled
);
94 case ComboBoxState
.Hot
:
95 return new VisualStyleRenderer (VisualStyleElement
.ComboBox
.DropDownButton
.Hot
);
96 case ComboBoxState
.Normal
:
98 return new VisualStyleRenderer (VisualStyleElement
.ComboBox
.DropDownButton
.Normal
);
99 case ComboBoxState
.Pressed
:
100 return new VisualStyleRenderer (VisualStyleElement
.ComboBox
.DropDownButton
.Pressed
);
104 private static VisualStyleRenderer
GetTextBoxRenderer (ComboBoxState state
)
107 case ComboBoxState
.Disabled
:
108 return new VisualStyleRenderer (VisualStyleElement
.TextBox
.TextEdit
.Disabled
);
109 case ComboBoxState
.Hot
:
110 return new VisualStyleRenderer (VisualStyleElement
.TextBox
.TextEdit
.Hot
);
111 case ComboBoxState
.Normal
:
112 case ComboBoxState
.Pressed
:
114 return new VisualStyleRenderer (VisualStyleElement
.TextBox
.TextEdit
.Normal
);
119 #region Public Static Properties
120 public static bool IsSupported
{
121 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }