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 // Jackson Harper (jackson@ximian.com)
29 using System.ComponentModel;
30 using System.ComponentModel.Design;
32 using System.Drawing.Imaging;
33 using System.Runtime.InteropServices;
35 namespace System.Windows.Forms {
36 [DefaultProperty("Image")]
37 [Designer("System.Windows.Forms.Design.PictureBoxDesigner, " + Consts.AssemblySystem_Design)]
38 public class PictureBox : Control {
41 private PictureBoxSizeMode size_mode;
44 private bool allow_drop;
46 private EventHandler frame_handler;
55 [DefaultValue(PictureBoxSizeMode.Normal)]
57 [RefreshProperties(RefreshProperties.Repaint)]
58 public PictureBoxSizeMode SizeMode {
59 get { return size_mode; }
61 if (size_mode == value)
68 OnSizeModeChanged (EventArgs.Empty);
81 if (image != null && ImageAnimator.CanAnimate (image)) {
82 frame_handler = new EventHandler (OnAnimateImage);
83 ImageAnimator.Animate (image, frame_handler);
90 [DefaultValue(BorderStyle.None)]
92 public BorderStyle BorderStyle {
93 get { return border_style; }
101 [EditorBrowsable(EditorBrowsableState.Never)]
102 public new bool CausesValidation {
103 get { return base.CausesValidation; }
104 set { base.CausesValidation = value; }
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public new ImeMode ImeMode {
110 get { return base.ImeMode; }
111 set { base.ImeMode = value; }
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public override RightToLeft RightToLeft {
117 get { return base.RightToLeft; }
118 set { base.RightToLeft = value; }
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 public new int TabIndex {
124 get { return base.TabIndex; }
125 set { base.TabIndex = value; }
129 [EditorBrowsable(EditorBrowsableState.Never)]
130 public new bool TabStop {
131 get { return base.TabStop; }
132 set { base.TabStop = value; }
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public override string Text {
139 get { return base.Text; }
140 set { base.Text = value; }
143 protected override CreateParams CreateParams {
145 return base.CreateParams;
149 protected override ImeMode DefaultImeMode {
150 get { return base.DefaultImeMode; }
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public override Font Font {
156 get { return base.Font; }
157 set { base.Font = value; }
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public override Color ForeColor {
163 get { return base.ForeColor; }
164 set { base.ForeColor = value; }
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 public override bool AllowDrop {
174 if (allow_drop != value) {
180 #region Protected Instance Methods
181 protected override Size DefaultSize {
182 get { return ThemeEngine.Current.PictureBoxDefaultSize; }
185 protected override void Dispose (bool disposing)
192 base.Dispose (disposing);
195 protected override void OnPaint (PaintEventArgs pe)
197 if (this.Width <= 0 || this.Height <= 0 || this.Visible == false)
201 pe.Graphics.DrawImage (this.ImageBuffer, pe.ClipRectangle, pe.ClipRectangle, GraphicsUnit.Pixel);
204 protected override void OnVisibleChanged (EventArgs e)
206 base.OnVisibleChanged (e);
210 protected virtual void OnSizeModeChanged (EventArgs e)
212 if (SizeModeChanged != null)
213 SizeModeChanged (this, e);
216 protected override void OnEnabledChanged (EventArgs e)
218 base.OnEnabledChanged (e);
221 protected override void OnParentChanged (EventArgs e)
223 base.OnParentChanged (e);
226 protected override void OnResize (EventArgs e)
231 if (size_mode == PictureBoxSizeMode.CenterImage || size_mode == PictureBoxSizeMode.StretchImage)
235 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
237 if (size_mode == PictureBoxSizeMode.AutoSize && image != null) {
239 height = image.Height;
241 base.SetBoundsCore (x, y, width, height, specified);
243 #endregion // Protected Instance Methods
245 #region Private Methods
246 private void StopAnimation ()
248 if (frame_handler == null)
250 ImageAnimator.StopAnimate (image, frame_handler);
251 frame_handler = null;
254 private void UpdateSize ()
258 if (size_mode == PictureBoxSizeMode.AutoSize)
259 ClientSize = image.Size;
262 private void Redraw (bool recalc)
265 this.recalc = recalc;
268 private void OnAnimateImage (object sender, EventArgs e)
270 // This is called from a worker thread,BeginInvoke is used
271 // so the control is updated from the correct thread
272 BeginInvoke (new EventHandler (UpdateAnimatedImage), new object [] { this, e });
275 private void UpdateAnimatedImage (object sender, EventArgs e)
277 ImageAnimator.UpdateFrames (image);
282 [MonoTODO ("Borders and stuff, and move into the Theme")]
286 ThemeEngine.Current.DrawPictureBox (DeviceContext, this);
290 #endregion // Private Methods
292 #region Public Instance Methods
293 public override string ToString() {
294 return base.ToString ();
300 [EditorBrowsable(EditorBrowsableState.Never)]
301 public new event EventHandler CausesValidationChanged {
302 add { base.CausesValidationChanged += value; }
303 remove { base.CausesValidationChanged -= value; }
307 [EditorBrowsable(EditorBrowsableState.Never)]
308 public new event EventHandler Enter {
309 add { base.Enter += value; }
310 remove { base.Enter -= value; }
314 [EditorBrowsable(EditorBrowsableState.Never)]
315 public new event EventHandler FontChanged {
316 add { base.FontChanged += value; }
317 remove { base.FontChanged -= value; }
321 [EditorBrowsable(EditorBrowsableState.Never)]
322 public new event EventHandler ForeColorChanged {
323 add { base.ForeColorChanged += value; }
324 remove { base.ForeColorChanged -= value; }
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 public new event EventHandler ImeModeChanged {
330 add { base.ImeModeChanged += value; }
331 remove { base.ImeModeChanged -= value; }
335 [EditorBrowsable(EditorBrowsableState.Never)]
336 public new event KeyEventHandler KeyDown {
337 add { base.KeyDown += value; }
338 remove { base.KeyDown -= value; }
342 [EditorBrowsable(EditorBrowsableState.Never)]
343 public new event KeyPressEventHandler KeyPress {
344 add { base.KeyPress += value; }
345 remove { base.KeyPress -= value; }
349 [EditorBrowsable(EditorBrowsableState.Never)]
350 public new event KeyEventHandler KeyUp {
351 add { base.KeyUp += value; }
352 remove { base.KeyUp -= value; }
356 [EditorBrowsable(EditorBrowsableState.Never)]
357 public new event EventHandler Leave {
358 add { base.Leave += value; }
359 remove { base.Leave -= value; }
363 [EditorBrowsable(EditorBrowsableState.Never)]
364 public new event EventHandler RightToLeftChanged {
365 add { base.RightToLeftChanged += value; }
366 remove { base.RightToLeftChanged -= value; }
370 [EditorBrowsable(EditorBrowsableState.Never)]
371 public new event EventHandler TabIndexChanged {
372 add { base.TabIndexChanged += value; }
373 remove { base.TabIndexChanged -= value; }
377 [EditorBrowsable(EditorBrowsableState.Never)]
378 public new event EventHandler TabStopChanged {
379 add { base.TabStopChanged += value; }
380 remove { base.TabStopChanged -= value; }
384 [EditorBrowsable(EditorBrowsableState.Never)]
385 public new event EventHandler TextChanged {
386 add { base.TextChanged += value; }
387 remove { base.TextChanged -= value; }
390 public event EventHandler SizeModeChanged;