(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / PictureBox.cs
blob8c067f97cefa0d7df66d6de48e0aec93f1a30d0b
1 //
2 // System.Windows.Forms.PicureBox
3 //
4 // Author:
5 // stubbed out by Hossein Safavi (hsafavi@purdue.edu)
6 // Dennis Hayes (dennish@raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
8 //
9 // (C) 2002 Ximian, Inc
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Drawing;
33 using System.ComponentModel;
35 namespace System.Windows.Forms {
37 //<summary>
38 //</summary>
39 public class PictureBox : Control {
41 Image image;
42 PictureBoxSizeMode sizeMode;
43 BorderStyle borderStyle;
45 public PictureBox ()
47 image = null;
48 sizeMode = PictureBoxSizeMode.Normal;
49 borderStyle = BorderStyle.None;
50 SetStyle ( ControlStyles.UserPaint, true );
51 SetStyle ( ControlStyles.Selectable, false );
54 public BorderStyle BorderStyle {
55 get { return borderStyle; }
56 set {
57 if ( !Enum.IsDefined ( typeof(BorderStyle), value ) )
58 throw new InvalidEnumArgumentException( "BorderStyle",
59 (int)value,
60 typeof(BorderStyle));
62 if ( borderStyle != value ) {
63 borderStyle = value;
64 RecreateHandle ( );
70 public Image Image {
71 get { return image; }
72 set {
73 image = value;
75 if ( sizeMode == PictureBoxSizeMode.AutoSize && image != null )
76 SetBounds ( 0, 0, 0, 0, BoundsSpecified.None );
78 Invalidate ( );
82 [EditorBrowsable (EditorBrowsableState.Never)]
83 public new ImeMode ImeMode {
84 get { return base.ImeMode; }
85 set { base.ImeMode = value;}
88 protected override CreateParams CreateParams {
89 get {
90 RegisterDefaultWindowClass ( );
92 CreateParams createParams = base.CreateParams;
94 createParams.ClassName = Win32.DEFAULT_WINDOW_CLASS;
96 createParams.Style |= (int) (
97 WindowStyles.WS_CHILD |
98 WindowStyles.WS_VISIBLE |
99 WindowStyles.WS_CLIPCHILDREN |
100 WindowStyles.WS_CLIPSIBLINGS );
102 switch ( BorderStyle ) {
103 case BorderStyle.Fixed3D:
104 createParams.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
105 break;
106 case BorderStyle.FixedSingle:
107 createParams.Style |= (int) WindowStyles.WS_BORDER;
108 break;
110 return createParams;
114 protected override ImeMode DefaultImeMode {
115 get { return ImeMode.Disable; }
118 protected override Size DefaultSize {
119 get { return new Size(100,50); }
122 public override string ToString()
124 return GetType( ).FullName.ToString ( ) + ", SizeMode: " + SizeMode.ToString ( );
127 public PictureBoxSizeMode SizeMode {
128 get { return sizeMode; }
129 set {
130 if ( !Enum.IsDefined ( typeof(PictureBoxSizeMode), value ) )
131 throw new InvalidEnumArgumentException( "SizeMode",
132 (int)value,
133 typeof( PictureBoxSizeMode ) );
135 if ( sizeMode != value ) {
136 sizeMode = value;
138 if ( sizeMode == PictureBoxSizeMode.AutoSize )
139 SetBounds ( 0, 0, 0, 0, BoundsSpecified.None );
141 SetStyle ( ControlStyles.AllPaintingInWmPaint, sizeMode == PictureBoxSizeMode.StretchImage );
143 Invalidate ( );
144 OnSizeModeChanged ( EventArgs.Empty );
150 [MonoTODO]
151 protected override void Dispose(bool disposing) {
152 base.Dispose(disposing);
155 [MonoTODO]
156 protected override void OnEnabledChanged(EventArgs e)
158 //FIXME:
159 base.OnEnabledChanged(e);
162 protected override void OnPaint(PaintEventArgs pe)
164 if ( Image != null ) {
165 switch ( SizeMode ) {
166 case PictureBoxSizeMode.StretchImage:
167 pe.Graphics.DrawImage ( Image, ClientRectangle );
168 break;
169 case PictureBoxSizeMode.CenterImage:
170 int dx = (ClientRectangle.Width - Image.Width)/2;
171 int dy = (ClientRectangle.Height- Image.Height)/2;
172 pe.Graphics.DrawImage ( Image, dx, dy );
173 break;
174 default:
175 pe.Graphics.DrawImage ( Image, 0, 0 );
176 break;
179 base.OnPaint(pe);
182 protected override void OnParentChanged(EventArgs e)
184 if ( Parent != null ) {
185 BackColor = Parent.BackColor;
186 Invalidate ( );
189 base.OnParentChanged(e);
192 protected override void OnResize(EventArgs e)
194 if ( SizeMode == PictureBoxSizeMode.CenterImage )
195 Invalidate ( );
196 else if ( SizeMode == PictureBoxSizeMode.StretchImage && IsHandleCreated)
197 Win32.InvalidateRect ( Handle, IntPtr.Zero, 0 );
199 base.OnResize(e);
202 protected virtual void OnSizeModeChanged(EventArgs e)
204 if ( SizeModeChanged != null )
205 SizeModeChanged ( this, e );
208 [MonoTODO]
209 protected override void OnVisibleChanged(EventArgs e)
211 base.OnVisibleChanged ( e );
214 [MonoTODO]
215 //this should be inherited.
216 protected override void OnPaintBackground (PaintEventArgs e) {
217 if ( SizeMode != PictureBoxSizeMode.StretchImage )
218 base.OnPaintBackground ( e );
221 protected override void SetBoundsCore(int x,int y,int width,int height,BoundsSpecified specified)
223 if ( SizeMode == PictureBoxSizeMode.AutoSize && Image != null ) {
224 width = Image.Width;
225 height= Image.Height;
226 specified = BoundsSpecified.Size;
229 base.SetBoundsCore(x, y, width, height, specified);
232 public event EventHandler SizeModeChanged;