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.
23 // Jonathan Chambers (jonathan.chambers@ansys.com)
31 namespace System
.Windows
.Forms
.PropertyGridInternal
{
32 internal class PropertyGridTextBox
: System
.Windows
.Forms
.UserControl
{
33 #region Private Members
35 private TextBox textbox
;
36 private Button dialog_button
;
37 private Button dropdown_button
;
39 #endregion Private Members
42 public PropertyGridTextBox() {
43 dialog_button
= new Button();
44 dropdown_button
= new Button();
45 textbox
= new TextBox();
49 dialog_button
.Dock
= DockStyle
.Right
;
50 dialog_button
.Size
= new Size(16, 16);
51 dialog_button
.TabIndex
= 1;
52 dialog_button
.Visible
= false;
53 dialog_button
.Click
+= new System
.EventHandler(dialog_button_Click
);
55 dropdown_button
.Dock
= DockStyle
.Right
;
56 dropdown_button
.Size
= new Size(16, 16);
57 dropdown_button
.TabIndex
= 2;
58 dropdown_button
.Visible
= false;
59 dropdown_button
.Click
+= new System
.EventHandler(dropdown_button_Click
);
61 textbox
.AutoSize
= false;
62 // this is to explicitly set bgcolor to avoid
63 // default ReadOnly color (which makes grid item
64 // bgcolor inconsistent).
65 textbox
.BackColor
= textbox
.BackColor
;
66 textbox
.BorderStyle
= BorderStyle
.None
;
67 textbox
.Dock
= DockStyle
.Fill
;
70 Controls
.Add(textbox
);
71 Controls
.Add(dropdown_button
);
72 Controls
.Add(dialog_button
);
76 dropdown_button
.Paint
+=new PaintEventHandler(dropdown_button_Paint
);
77 dialog_button
.Paint
+=new PaintEventHandler(dialog_button_Paint
);
78 textbox
.DoubleClick
+=new EventHandler(textbox_DoubleClick
);
82 #endregion Contructors
84 #region Public Instance Properties
86 public bool DialogButtonVisible
{
88 return dialog_button
.Visible
;
91 dialog_button
.Visible
= value;
94 public bool DropDownButtonVisible
{
96 return dropdown_button
.Visible
;
99 dropdown_button
.Visible
= value;
103 public bool ReadOnly
{
105 return textbox
.ReadOnly
;
108 textbox
.ReadOnly
= value;
112 public new string Text
{
117 textbox
.Text
= value;
121 #endregion Public Instance Properties
124 static object DropDownButtonClickedEvent
= new object ();
125 static object DialogButtonClickedEvent
= new object ();
126 static object ToggleValueEvent
= new object ();
128 public event EventHandler DropDownButtonClicked
{
129 add { Events.AddHandler (DropDownButtonClickedEvent, value); }
130 remove { Events.RemoveHandler (DropDownButtonClickedEvent, value); }
133 public event EventHandler DialogButtonClicked
{
134 add { Events.AddHandler (DialogButtonClickedEvent, value); }
135 remove { Events.RemoveHandler (DialogButtonClickedEvent, value); }
138 public event EventHandler ToggleValue
{
139 add { Events.AddHandler (ToggleValueEvent, value); }
140 remove { Events.RemoveHandler (ToggleValueEvent, value); }
145 #region Private Helper Methods
147 private void dropdown_button_Paint(object sender
, PaintEventArgs e
)
149 ThemeEngine
.Current
.CPDrawComboButton(e
.Graphics
, dropdown_button
.ClientRectangle
, dropdown_button
.ButtonState
);
152 private void dialog_button_Paint(object sender
, PaintEventArgs e
) {
153 // best way to draw the ellipse?
154 e
.Graphics
.DrawString("...", new Font(Font
,FontStyle
.Bold
), Brushes
.Black
, 0,0);
157 private void dropdown_button_Click(object sender
, EventArgs e
) {
158 EventHandler eh
= (EventHandler
)(Events
[DropDownButtonClickedEvent
]);
163 private void dialog_button_Click(object sender
, EventArgs e
) {
164 EventHandler eh
= (EventHandler
)(Events
[DialogButtonClickedEvent
]);
169 #endregion Private Helper Methods
171 private void textbox_DoubleClick(object sender
, EventArgs e
) {
172 EventHandler eh
= (EventHandler
)(Events
[ToggleValueEvent
]);