ColumnHeader.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Author:
  23. // Ravindra ([email protected])
  24. //
  25. // $Revision: 1.2 $
  26. // $Modtime: $
  27. // $Log: ColumnHeader.cs,v $
  28. // Revision 1.2 2004/10/15 15:06:44 ravindra
  29. // Flushing some formatting changes.
  30. //
  31. // Revision 1.1 2004/09/30 13:25:33 ravindra
  32. // Supporting class for ListView control.
  33. //
  34. //
  35. // COMPLETE
  36. //
  37. using System.ComponentModel;
  38. using System.Drawing;
  39. namespace System.Windows.Forms
  40. {
  41. [DefaultProperty ("Text")]
  42. [DesignTimeVisible (false)]
  43. [ToolboxItem (false)]
  44. public class ColumnHeader : Component, ICloneable
  45. {
  46. #region Instance Variables
  47. internal ListView owner;
  48. private string text = "ColumnHeader";
  49. private HorizontalAlignment textAlignment = HorizontalAlignment.Left;
  50. private int width = 60;
  51. #endregion // Instance Variables
  52. #region Internal Constructor
  53. internal ColumnHeader (ListView owner, string text, HorizontalAlignment alignment, int width)
  54. {
  55. this.owner = owner;
  56. this.text = text;
  57. this.width = width;
  58. this.textAlignment = alignment;
  59. }
  60. #endregion // Internal Constructor
  61. #region Public Constructors
  62. public ColumnHeader () { }
  63. #endregion // Public Constructors
  64. #region Public Instance Properties
  65. [Browsable (false)]
  66. public int Index {
  67. get {
  68. if (owner != null && owner.Columns != null
  69. && owner.Columns.Contains (this)) {
  70. return owner.Columns.IndexOf (this);
  71. }
  72. return -1;
  73. }
  74. }
  75. [Browsable (false)]
  76. public ListView ListView {
  77. get { return owner; }
  78. }
  79. [Localizable (true)]
  80. public string Text {
  81. get { return text; }
  82. set { text = value; }
  83. }
  84. [DefaultValue (HorizontalAlignment.Left)]
  85. [Localizable (true)]
  86. public HorizontalAlignment TextAlign {
  87. get { return textAlignment; }
  88. set { textAlignment = value; }
  89. }
  90. [DefaultValue (60)]
  91. [Localizable (true)]
  92. public int Width {
  93. get { return width; }
  94. set { width = value; }
  95. }
  96. #endregion // Public Instance Properties
  97. #region Public Methods
  98. public virtual object Clone ()
  99. {
  100. ColumnHeader columnHeader = new ColumnHeader ();
  101. columnHeader.Text = text;
  102. columnHeader.TextAlign = textAlignment;
  103. columnHeader.Width = width;
  104. columnHeader.owner = owner;
  105. return columnHeader;
  106. }
  107. public override string ToString ()
  108. {
  109. return string.Format ("ColumnHeader: Text: {0}", text);
  110. }
  111. #endregion // Public Methods
  112. #region Protected Methods
  113. protected override void Dispose (bool disposing)
  114. {
  115. base.Dispose (disposing);
  116. }
  117. #endregion // Protected Methods
  118. }
  119. }