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