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 Novell, Inc.
23 // Jackson Harper (jackson@ximian.com)
29 using System.Drawing.Imaging;
31 namespace System.Windows.Forms {
33 public class PictureBox : Control {
36 private PictureBoxSizeMode size_mode;
37 private BorderStyle border_style;
41 private EventHandler frame_handler;
49 public PictureBoxSizeMode SizeMode {
50 get { return size_mode; }
52 if (size_mode == value)
68 if (image != null && ImageAnimator.CanAnimate (image)) {
69 frame_handler = new EventHandler (OnAnimateImage);
70 ImageAnimator.Animate (image, frame_handler);
77 public BorderStyle BorderStyle {
78 get { return border_style; }
85 public new bool CausesValidation {
86 get { return base.CausesValidation; }
87 set { base.CausesValidation = value; }
90 public new ImeMode ImeMode {
91 get { return base.ImeMode; }
92 set { base.ImeMode = value; }
95 public override RightToLeft RightToLeft {
96 get { return base.RightToLeft; }
97 set { base.RightToLeft = value; }
100 public new int TabIndex {
101 get { return base.TabIndex; }
102 set { base.TabIndex = value; }
105 public new bool TabStop {
106 get { return base.TabStop; }
107 set { base.TabStop = value; }
110 public override string Text {
111 get { return base.Text; }
112 set { base.Text = value; }
115 protected override CreateParams CreateParams {
117 return base.CreateParams;
121 protected override ImeMode DefaultImeMode {
122 get { return base.DefaultImeMode; }
125 public override Font Font {
126 get { return base.Font; }
127 set { base.Font = value; }
130 public override Color ForeColor {
131 get { return base.ForeColor; }
132 set { base.ForeColor = value; }
135 protected override Size DefaultSize {
136 get { return ThemeEngine.Current.PictureBoxDefaultSize; }
139 protected override void Dispose (bool disposing)
146 base.Dispose (disposing);
149 protected override void OnPaint (PaintEventArgs pe)
151 if (this.Width <= 0 || this.Height <= 0 || this.Visible == false)
155 pe.Graphics.DrawImage (this.ImageBuffer, pe.ClipRectangle, pe.ClipRectangle, GraphicsUnit.Pixel);
158 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
160 if (size_mode == PictureBoxSizeMode.AutoSize && image != null) {
162 height = image.Height;
164 base.SetBoundsCore (x, y, width, height, specified);
167 private void StopAnimation ()
169 if (frame_handler == null)
171 ImageAnimator.StopAnimate (image, frame_handler);
172 frame_handler = null;
175 private void UpdateSize ()
179 if (size_mode == PictureBoxSizeMode.AutoSize)
180 ClientSize = image.Size;
183 private void Redraw (bool recalc)
186 this.recalc = recalc;
189 private void OnAnimateImage (object sender, EventArgs e)
191 // This is called from a worker thread,BeginInvoke is used
192 // so the control is updated from the correct thread
193 BeginInvoke (new EventHandler (UpdateAnimatedImage), new object [] { this, e });
196 private void UpdateAnimatedImage (object sender, EventArgs e)
198 ImageAnimator.UpdateFrames (image);
203 [MonoTODO ("Borders and stuff, and move into the Theme")]
207 ThemeEngine.Current.DrawPictureBox (DeviceContext, this);