* Test/System.Windows.Forms/DataGridViewCellTest.cs: Added
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Label.cs
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
19 //
20 // Copyright (c) 2004-2006 Novell, Inc.
21 //
22 // Authors:
23 //      Jordi Mas i Hernandez, jordi@ximian.com
24 //      Peter Bartok, pbartok@novell.com
25 //
26 //
27
28 // COMPLETE
29
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32 using System.Drawing;
33 using System.Drawing.Text;
34 using System.Drawing.Imaging;
35 using System.Runtime.InteropServices;
36
37 namespace System.Windows.Forms
38 {
39         [DefaultProperty ("Text")]
40         [Designer ("System.Windows.Forms.Design.LabelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
41 #if NET_2_0
42         [ClassInterface (ClassInterfaceType.AutoDispatch)]
43         [ComVisible (true)]
44         [ToolboxItem ("System.Windows.Forms.Design.AutoSizeToolboxItem," + Consts.AssemblySystem_Design)]
45         [DefaultBindingProperty ("Text")]
46 #endif
47         public class Label : Control
48         {
49                 private bool autosize;
50 #if NET_2_0
51                 private bool auto_ellipsis;
52 #endif
53                 private Image image;
54                 private bool render_transparent;
55                 private FlatStyle flat_style;
56                 private bool use_mnemonic;
57                 private int image_index = -1;
58 #if NET_2_0
59                 private string image_key = string.Empty;
60 #endif
61                 private ImageList image_list;
62                 internal ContentAlignment image_align;
63                 internal StringFormat string_format;
64                 internal ContentAlignment text_align;
65                 static SizeF req_witdthsize = new SizeF (0,0);
66
67                 #region Events
68                 static object AutoSizeChangedEvent = new object ();
69                 static object TextAlignChangedEvent = new object ();
70
71 #if NET_2_0
72
73                 [Browsable (true)]
74                 [EditorBrowsable (EditorBrowsableState.Always)]
75 #endif
76                 public new event EventHandler AutoSizeChanged {
77                         add { Events.AddHandler (AutoSizeChangedEvent, value); }
78                         remove { Events.RemoveHandler (AutoSizeChangedEvent, value); }
79                 }
80
81                 [Browsable(false)]
82                 [EditorBrowsable(EditorBrowsableState.Never)]
83                 public new event EventHandler BackgroundImageChanged {
84                         add { base.BackgroundImageChanged += value; }
85                         remove { base.BackgroundImageChanged -= value; }
86                 }
87
88 #if NET_2_0
89                 [Browsable (false)]
90                 [EditorBrowsable (EditorBrowsableState.Never)]
91                 public new event EventHandler BackgroundImageLayoutChanged {
92                         add { base.BackgroundImageLayoutChanged += value; }
93                         remove { base.BackgroundImageLayoutChanged -= value; }
94                 }
95 #endif
96
97                 [Browsable(false)]
98                 [EditorBrowsable(EditorBrowsableState.Never)]
99                 public new event EventHandler ImeModeChanged {
100                         add { base.ImeModeChanged += value; }
101                         remove { base.ImeModeChanged -= value; }
102                 }
103
104                 [Browsable(false)]
105                 [EditorBrowsable(EditorBrowsableState.Never)]
106                 public new event KeyEventHandler KeyDown {
107                         add { base.KeyDown += value; }
108                         remove { base.KeyDown -= value; }
109                 }
110
111                 [Browsable(false)]
112                 [EditorBrowsable(EditorBrowsableState.Never)]
113                 public new event KeyPressEventHandler KeyPress {
114                         add { base.KeyPress += value; }
115                         remove { base.KeyPress -= value; }
116                 }
117
118                 [Browsable(false)]
119                 [EditorBrowsable(EditorBrowsableState.Never)]
120                 public new event KeyEventHandler KeyUp {
121                         add { base.KeyUp += value; }
122                         remove { base.KeyUp -= value; }
123                 }
124
125                 [Browsable(false)]
126                 [EditorBrowsable(EditorBrowsableState.Never)]
127                 public new event EventHandler TabStopChanged {
128                         add { base.TabStopChanged += value; }
129                         remove { base.TabStopChanged -= value; }
130                 }
131
132                 public event EventHandler TextAlignChanged {
133                         add { Events.AddHandler (TextAlignChangedEvent, value); }
134                         remove { Events.RemoveHandler (TextAlignChangedEvent, value); }
135                 }
136                 #endregion
137
138                 public Label ()
139                 {
140                         // Defaults in the Spec
141                         autosize = false;
142                         TabStop = false;
143                         string_format = new StringFormat();
144                         TextAlign = ContentAlignment.TopLeft;
145                         image = null;
146                         UseMnemonic = true;
147                         image_list = null;
148                         image_align = ContentAlignment.MiddleCenter;
149                         SetUseMnemonic (UseMnemonic);
150                         flat_style = FlatStyle.Standard;
151
152                         SetStyle (ControlStyles.Selectable, false);
153                         SetStyle (ControlStyles.ResizeRedraw | 
154                                 ControlStyles.UserPaint | 
155                                 ControlStyles.AllPaintingInWmPaint |
156                                 ControlStyles.SupportsTransparentBackColor
157 #if NET_2_0
158                                 | ControlStyles.OptimizedDoubleBuffer
159 #else
160                                 | ControlStyles.DoubleBuffer
161 #endif
162                                 , true);
163                         
164                         HandleCreated += new EventHandler (OnHandleCreatedLB);
165                 }
166
167                 #region Public Properties
168
169 #if NET_2_0
170                 [DefaultValue (false)]
171                 [Browsable (true)]
172                 [EditorBrowsable (EditorBrowsableState.Always)]
173                 public bool AutoEllipsis
174                 {
175                         get { return this.auto_ellipsis; }
176                         set
177                         {
178                                 if (this.auto_ellipsis != value) {
179                                         this.auto_ellipsis = value;
180
181                                         if (this.auto_ellipsis)
182                                                 string_format.Trimming = StringTrimming.EllipsisCharacter;
183                                         else
184                                                 string_format.Trimming = StringTrimming.Character;
185
186                                         this.Invalidate ();
187                                 }
188                         }
189                 }
190 #endif
191
192                 [DefaultValue(false)]
193                 [Localizable(true)]
194                 [RefreshProperties(RefreshProperties.All)]
195 #if NET_2_0
196                 [Browsable (true)]
197                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
198                 [EditorBrowsable (EditorBrowsableState.Always)]
199 #endif
200                 public new virtual bool AutoSize {
201                         get { return autosize; }
202                         set {
203                                 if (autosize == value)
204                                         return;
205
206 #if NET_2_0
207                                 base.SetAutoSizeMode (AutoSizeMode.GrowAndShrink);
208                                 base.AutoSize = value;
209 #endif
210                                 autosize = value;
211                                 CalcAutoSize ();
212                                 Invalidate ();
213
214                                 OnAutoSizeChanged (EventArgs.Empty);                                    
215                         }
216                 }
217
218                 [Browsable(false)]
219                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
220                 [EditorBrowsable(EditorBrowsableState.Never)]
221                 public override Image BackgroundImage {
222                         get { return base.BackgroundImage; }
223                         set {
224                                 base.BackgroundImage = value;
225                                 Invalidate ();
226                         }
227                 }
228
229 #if NET_2_0
230                 [Browsable (false)]
231                 [EditorBrowsable (EditorBrowsableState.Never)]
232                 public override ImageLayout BackgroundImageLayout {
233                         get { return base.BackgroundImageLayout; }
234                         set { base.BackgroundImageLayout = value; }
235                 }
236 #endif
237         
238                 [DefaultValue(BorderStyle.None)]
239                 [DispId(-504)]
240                 public virtual BorderStyle BorderStyle {
241                         get { return InternalBorderStyle; }
242                         set { InternalBorderStyle = value; }
243                 }
244
245                 protected override CreateParams CreateParams {
246                         get { 
247                                 CreateParams create_params = base.CreateParams;
248                                         
249                                 if (BorderStyle != BorderStyle.Fixed3D)
250                                         return create_params;
251                                         
252                                 create_params.ExStyle &= ~(int) WindowExStyles.WS_EX_CLIENTEDGE;
253                                 create_params.ExStyle |= (int)WindowExStyles.WS_EX_STATICEDGE;
254                                         
255                                 return create_params;
256                         }
257                 }
258
259                 protected override ImeMode DefaultImeMode {
260                         get { return ImeMode.Disable;}
261                 }
262
263 #if NET_2_0
264                 protected override Padding DefaultMargin {
265                         get { return new Padding (3, 0, 3, 0); }
266                 }
267 #endif
268
269                 protected override Size DefaultSize {
270                         get {return ThemeEngine.Current.LabelDefaultSize;}
271                 }
272
273                 [DefaultValue(FlatStyle.Standard)]
274                 public FlatStyle FlatStyle {
275                         get { return flat_style; }
276                         set {
277                                 if (!Enum.IsDefined (typeof (FlatStyle), value))
278                                         throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for FlatStyle", value));
279
280                                 if (flat_style == value)
281                                         return;
282
283                                 flat_style = value;
284                                 Invalidate ();
285                         }
286                 }
287
288                 [Localizable(true)]
289                 public Image Image {
290                         get {
291                                 if (this.image != null)
292                                         return this.image;
293
294                                 if (this.image_index >= 0)
295                                         if (this.image_list != null)
296                                                 return this.image_list.Images[this.image_index];
297
298 #if NET_2_0
299                                 if (!string.IsNullOrEmpty (this.image_key))
300                                         if (this.image_list != null)
301                                                 return this.image_list.Images[this.image_key];
302 #endif
303                                 return null;
304                         }
305                         set {
306                                 if (this.image != value) {
307                                         this.image = value;
308                                         this.image_index = -1;
309 #if NET_2_0
310                                         this.image_key = string.Empty;
311 #endif
312                                         this.image_list = null;
313
314 #if NET_2_0
315                                         if (this.AutoSize && this.Parent != null)
316                                                 this.Parent.PerformLayout (this, "Image");
317 #endif
318
319                                         Invalidate ();
320                                 }
321                         }
322                 }
323
324                 [DefaultValue(ContentAlignment.MiddleCenter)]
325                 [Localizable(true)]
326                 public ContentAlignment ImageAlign {
327                         get { return image_align; }
328                         set {
329                                 if (!Enum.IsDefined (typeof (ContentAlignment), value))
330                                         throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for ContentAlignment", value));
331
332                                 if (image_align == value)
333                                         return;
334
335                                 image_align = value;
336                                 Invalidate ();
337                         }
338                 }
339
340                 [DefaultValue (-1)]
341                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
342                 [Localizable (true)]
343                 [TypeConverter (typeof (ImageIndexConverter))]
344 #if NET_2_0
345                 [RefreshProperties (RefreshProperties.Repaint)]
346 #endif
347                 public int ImageIndex {
348                         get { 
349                                 if (ImageList == null) {
350                                         return -1;
351                                 }
352                                         
353                                 if (image_index >= image_list.Images.Count) {
354                                         return image_list.Images.Count - 1;
355                                 }
356                                         
357                                 return image_index;
358                         }
359                         set {
360
361                                 if (value < -1)
362                                         throw new ArgumentException ();
363
364                                 if (this.image_index != value) {
365                                         this.image_index = value;
366                                         this.image = null;
367 #if NET_2_0
368                                         this.image_key = string.Empty;
369 #endif
370                                         Invalidate ();
371                                 }
372                         }
373                 }
374
375 #if NET_2_0
376                 [Localizable (true)]
377                 [DefaultValue ("")]
378                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
379                 [RefreshProperties (RefreshProperties.Repaint)]
380                 [TypeConverter (typeof (ImageKeyConverter))]
381                 public string ImageKey {
382                         get { return this.image_key; }
383                         set {
384                                 if (this.image_key != value) {
385                                         this.image = null;
386                                         this.image_index = -1;
387                                         this.image_key = value;
388                                         this.Invalidate ();
389                                 }
390                         }
391                 }
392 #endif
393
394                 [DefaultValue(null)]
395 #if NET_2_0
396                 [RefreshProperties (RefreshProperties.Repaint)]
397 #endif
398                 public ImageList ImageList {
399                         get { return image_list;}
400                         set {
401                                 if (image_list == value)
402                                         return;
403                                         
404                                 image_list = value;
405
406                                 if (image_list != null && image_index !=-1)
407                                         Image = null;
408
409                                 Invalidate ();
410                         }
411                 }
412
413                 [Browsable(false)]
414                 [EditorBrowsable(EditorBrowsableState.Never)]
415                 public new ImeMode ImeMode {
416                         get { return base.ImeMode; }
417                         set { base.ImeMode = value; }
418                 }
419
420                 internal virtual Size InternalGetPreferredSize (Size proposed)
421                 {
422                         Size size;
423
424                         if (Text == string.Empty) {
425                                 size = new Size (0, Font.Height);
426                         } else {
427                                 size = Size.Ceiling (TextRenderer.MeasureString (Text, Font, req_witdthsize, string_format));
428                                 size.Width += 3;
429                         }
430
431 #if NET_2_0
432                         if (!use_compatible_text_rendering)
433                                 return size;
434 #else
435                                 size.Height = Font.Height;
436 #endif
437
438                         if (border_style == BorderStyle.None)
439                                 size.Height += 3;
440                         else
441                                 size.Height += 6;
442                         
443                         return size;
444                 }
445
446 #if NET_2_0
447                 public override Size GetPreferredSize (Size proposed)
448                 {
449                         return InternalGetPreferredSize (proposed);
450                 }
451 #endif
452
453                 [Browsable(false)]
454                 [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
455                 [EditorBrowsable(EditorBrowsableState.Advanced)]
456                 public virtual int PreferredHeight {
457                         get { return InternalGetPreferredSize (Size.Empty).Height; }
458                 }
459
460                 [Browsable(false)]
461                 [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
462                 [EditorBrowsable(EditorBrowsableState.Advanced)]
463                 public virtual int PreferredWidth {
464                         get { return InternalGetPreferredSize (Size.Empty).Width; }
465                 }
466
467 #if NET_2_0
468                 [Obsolete ("This property has been deprecated.  Use BackColor instead.")]
469 #endif
470                 protected virtual bool RenderTransparent {
471                         get { return render_transparent; }
472                         set { render_transparent = value;}
473                 }
474                         
475                 [Browsable(false)]
476                 [DefaultValue(false)]
477                 [EditorBrowsable(EditorBrowsableState.Never)]
478                 public new bool TabStop  {
479                         get { return base.TabStop; }
480                         set { base.TabStop = value; }
481                 }
482
483                 [DefaultValue(ContentAlignment.TopLeft)]
484                 [Localizable(true)]
485                 public virtual ContentAlignment TextAlign {
486                         get { return text_align; }
487
488                         set {
489                                 if (!Enum.IsDefined (typeof (ContentAlignment), value))
490                                         throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for ContentAlignment", value));
491
492                                         if (text_align != value) {
493
494                                                 text_align = value;
495
496                                                 switch (value) {
497
498                                                 case ContentAlignment.BottomLeft:
499                                                         string_format.LineAlignment = StringAlignment.Far;
500                                                         string_format.Alignment = StringAlignment.Near;
501                                                         break;
502                                                 case ContentAlignment.BottomCenter:
503                                                         string_format.LineAlignment = StringAlignment.Far;
504                                                         string_format.Alignment = StringAlignment.Center;
505                                                         break;
506                                                 case ContentAlignment.BottomRight:
507                                                         string_format.LineAlignment = StringAlignment.Far;
508                                                 string_format.Alignment = StringAlignment.Far;
509                                                 break;
510                                         case ContentAlignment.TopLeft:
511                                                 string_format.LineAlignment = StringAlignment.Near;
512                                                 string_format.Alignment = StringAlignment.Near;
513                                                 break;
514                                         case ContentAlignment.TopCenter:
515                                                 string_format.LineAlignment = StringAlignment.Near;
516                                                 string_format.Alignment = StringAlignment.Center;
517                                                 break;
518                                         case ContentAlignment.TopRight:
519                                                 string_format.LineAlignment = StringAlignment.Near;
520                                                 string_format.Alignment = StringAlignment.Far;
521                                                 break;
522                                         case ContentAlignment.MiddleLeft:
523                                                 string_format.LineAlignment = StringAlignment.Center;
524                                                 string_format.Alignment = StringAlignment.Near;
525                                                 break;
526                                                 case ContentAlignment.MiddleRight:
527                                                         string_format.LineAlignment = StringAlignment.Center;
528                                                         string_format.Alignment = StringAlignment.Far;
529                                                         break;
530                                                 case ContentAlignment.MiddleCenter:
531                                                         string_format.LineAlignment = StringAlignment.Center;
532                                                         string_format.Alignment = StringAlignment.Center;
533                                                 break;
534                                         default:
535                                                 break;
536                                         }
537
538                                         OnTextAlignChanged (EventArgs.Empty);
539                                         Invalidate ();
540                                 }
541                         }
542                 }
543
544                 [DefaultValue(true)]
545                 public bool UseMnemonic {
546                         get { return use_mnemonic; }
547                         set {
548                                 if (use_mnemonic != value) {
549                                         use_mnemonic = value;
550                                         SetUseMnemonic (use_mnemonic);
551                                         Invalidate ();
552                                 }
553                         }
554                 }
555
556                 #endregion
557
558                 #region Public Methods
559
560                 protected Rectangle CalcImageRenderBounds (Image image, Rectangle area, ContentAlignment img_align)
561                 {
562                                 Rectangle rcImageClip = area;
563                         rcImageClip.Inflate (-2,-2);
564
565                         int X = area.X;
566                         int Y = area.Y;
567
568                         if (img_align == ContentAlignment.TopCenter ||
569                                 img_align == ContentAlignment.MiddleCenter ||
570                                 img_align == ContentAlignment.BottomCenter) {
571                                 X += (area.Width - image.Width) / 2;
572                         }
573                         else if (img_align == ContentAlignment.TopRight ||
574                                 img_align == ContentAlignment.MiddleRight||
575                                 img_align == ContentAlignment.BottomRight) {
576                                 X += (area.Width - image.Width);
577                         }
578
579                         if( img_align == ContentAlignment.BottomCenter ||
580                                 img_align == ContentAlignment.BottomLeft ||
581                                 img_align == ContentAlignment.BottomRight) {
582                                 Y += area.Height - image.Height;
583                         }
584                         else if(img_align == ContentAlignment.MiddleCenter ||
585                                         img_align == ContentAlignment.MiddleLeft ||
586                                         img_align == ContentAlignment.MiddleRight) {
587                                 Y += (area.Height - image.Height) / 2;
588                         }
589
590                         rcImageClip.X = X;
591                         rcImageClip.Y = Y;
592                         rcImageClip.Width = image.Width;
593                         rcImageClip.Height = image.Height;
594
595                         return rcImageClip;
596                 }
597
598                 protected override AccessibleObject CreateAccessibilityInstance ()
599                 {
600                         return base.CreateAccessibilityInstance ();
601                 }
602
603                 protected override void Dispose(bool disposing)
604                 {
605                         base.Dispose (disposing);
606
607                         if (disposing)
608                                 string_format.Dispose ();
609                 }
610
611                 protected void DrawImage (Graphics g, Image image, Rectangle area, ContentAlignment img_align)
612                 {
613                         if (image == null || g == null)
614                                 return;
615
616                         Rectangle rcImageClip = CalcImageRenderBounds (image, area, img_align);
617
618                         if (Enabled)
619                                 g.DrawImage (image, rcImageClip.X, rcImageClip.Y, rcImageClip.Width, rcImageClip.Height);
620                         else
621                                 ControlPaint.DrawImageDisabled (g, image, rcImageClip.X, rcImageClip.Y, BackColor);
622                 }
623
624 #if !NET_2_0
625                 protected virtual void OnAutoSizeChanged (EventArgs e)
626                 {
627                         EventHandler eh = (EventHandler)(Events [AutoSizeChangedEvent]);
628                         if (eh != null)
629                                 eh (this, e);
630                 }
631 #endif
632
633                 protected override void OnEnabledChanged (EventArgs e)
634                 {
635                         base.OnEnabledChanged (e);
636                 }
637
638                 protected override void OnFontChanged (EventArgs e)
639                 {
640                         base.OnFontChanged (e);
641                         if (autosize)
642                                 CalcAutoSize();
643                         Invalidate ();
644                 }
645
646 #if NET_2_0
647                 protected override void OnPaddingChanged (EventArgs e)
648                 {
649                         base.OnPaddingChanged (e);
650                 }
651 #endif
652
653                 protected override void OnPaint (PaintEventArgs pevent)
654                 {
655                         ThemeEngine.Current.DrawLabel (pevent.Graphics, ClientRectangle, this);
656                         DrawImage (pevent.Graphics, Image, ClientRectangle, image_align);
657                         base.OnPaint(pevent);
658                 }
659
660                 protected override void OnParentChanged (EventArgs e)
661                 {
662                                 base.OnParentChanged (e);
663                 }
664
665 #if NET_2_0
666                 protected override void OnRightToLeftChanged (EventArgs e)
667                 {
668                         base.OnRightToLeftChanged (e);
669                 }
670 #endif
671
672                 protected virtual void OnTextAlignChanged (EventArgs e)
673                 {
674                         EventHandler eh = (EventHandler)(Events [TextAlignChangedEvent]);
675                         if (eh != null)
676                                 eh (this, e);
677                 }
678
679                 protected override void OnTextChanged (EventArgs e)
680                 {
681                         base.OnTextChanged (e);                 
682                         if (autosize)
683                                 CalcAutoSize ();
684                         Invalidate ();
685                 }
686
687                 protected override void OnVisibleChanged (EventArgs e)
688                 {
689                         base.OnVisibleChanged (e);
690                 }
691
692                 protected override bool ProcessMnemonic (char charCode)
693                 {
694                         if (IsMnemonic(charCode, Text) == true) {
695                                 // Select item next in line in tab order
696                                 if (this.Parent != null) {
697                                         Parent.SelectNextControl(this, true, false, false, false);
698                                 }
699                                 return true;
700                         }
701                         
702                         return base.ProcessMnemonic (charCode);
703                 }
704
705                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
706                 {
707                         base.SetBoundsCore (x, y, width, height, specified);
708                 }
709
710                 public override string ToString()
711                 {
712                         return base.ToString () + ", Text: " + Text;
713                 }
714
715                 protected override void WndProc (ref Message m)
716                 {
717                         switch ((Msg) m.Msg) {
718                                 case Msg.WM_DRAWITEM: {
719                                         m.Result = (IntPtr)1;
720                                 }
721                                         break;
722                                 default:
723                                         base.WndProc (ref m);
724                                         break;
725                         }
726                 }
727
728                 #endregion Public Methods
729
730                 #region Private Methods
731
732                 private void CalcAutoSize ()
733                 {
734                         if (!AutoSize)
735                                 return;
736
737                         Size s = InternalGetPreferredSize (Size.Empty);
738                         
739                         SetBounds (Left, Top, s.Width, s.Height, BoundsSpecified.None);
740                 }
741
742                 private void OnHandleCreatedLB (Object o, EventArgs e)
743                 {
744                         if (autosize)
745                                 CalcAutoSize ();
746                 }
747
748                 private void SetUseMnemonic (bool use)
749                 {
750                         if (use)
751                                 string_format.HotkeyPrefix = HotkeyPrefix.Show;
752                         else
753                                 string_format.HotkeyPrefix = HotkeyPrefix.None;
754                 }
755
756                 #endregion Private Methods
757 #if NET_2_0
758                 [DefaultValue (false)]
759                 public bool UseCompatibleTextRendering {
760                         get { return use_compatible_text_rendering; }
761                         set { use_compatible_text_rendering = value; }
762                 }
763
764                 [SettingsBindable (true)]
765                 [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
766                          typeof (System.Drawing.Design.UITypeEditor))]
767                 public override string Text {
768                         get { return base.Text; }
769                         set { base.Text = value; }
770                 }
771
772                 protected override void OnMouseEnter (EventArgs e)
773                 {
774                         base.OnMouseEnter (e);
775                 }
776
777                 protected override void OnMouseLeave (EventArgs e)
778                 {
779                         base.OnMouseLeave (e);
780                 }
781
782                 protected override void OnHandleDestroyed (EventArgs e)
783                 {
784                         base.OnHandleDestroyed (e);
785                 }
786 #endif
787
788         }
789 }