ColumnHeader.cs 3.4 KB

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