ColumnHeader ColumnHeader ColumnHeader ColumnHeader Class

定义

ListView 控件中显示一个列标题。Displays a single column header in a ListView control.

public ref class ColumnHeader : System::ComponentModel::Component, ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ColumnHeaderConverter))]
public class ColumnHeader : System.ComponentModel.Component, ICloneable
type ColumnHeader = class
    inherit Component
    interface ICloneable
Public Class ColumnHeader
Inherits Component
Implements ICloneable
继承
属性
实现

示例

下面的代码示例演示如何初始化ListView控件。The following code example demonstrates initializing a ListView control. 该示例创建ColumnHeader对象并设置列标题的TextTextAlignWidth属性。The example creates ColumnHeader objects and sets the column header's Text, TextAlign and Width properties. 该示例还向添加了ListView项和子项。The example also adds items and subitems to the ListView. 若要运行此示例, 请将以下代码粘贴到窗体PopulateListView中, 并从窗体的Load构造函数或事件处理程序调用方法。To run this example paste the following code in a form and call the PopulateListView method from the form's constructor or Load event handler.

private:
   void PopulateListView()
   {
      ListView1->Width = 270;
      ListView1->Location = System::Drawing::Point( 10, 10 );
      
      // Declare and construct the ColumnHeader objects.
      ColumnHeader^ header1;
      ColumnHeader^ header2;
      header1 = gcnew ColumnHeader;
      header2 = gcnew ColumnHeader;
      
      // Set the text, alignment and width for each column header.
      header1->Text = "File name";
      header1->TextAlign = HorizontalAlignment::Left;
      header1->Width = 70;
      header2->TextAlign = HorizontalAlignment::Left;
      header2->Text = "Location";
      header2->Width = 200;
      
      // Add the headers to the ListView control.
      ListView1->Columns->Add( header1 );
      ListView1->Columns->Add( header2 );
            
	  // Specify that each item appears on a separate line.
      ListView1->View = View::Details;

	  // Populate the ListView.Items property.
      // Set the directory to the sample picture directory.
      System::IO::DirectoryInfo^ dirInfo = gcnew System::IO::DirectoryInfo( "C:\\Documents and Settings\\All Users"
      "\\Documents\\My Pictures\\Sample Pictures" );
      
      // Get the .jpg files from the directory
      array<System::IO::FileInfo^>^files = dirInfo->GetFiles( "*.jpg" );
      
      // Add each file name and full name including path
      // to the ListView.
      if ( files != nullptr )
      {
         System::Collections::IEnumerator^ myEnum = files->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            System::IO::FileInfo^ file = safe_cast<System::IO::FileInfo^>(myEnum->Current);
            ListViewItem^ item = gcnew ListViewItem( file->Name );
            item->SubItems->Add( file->FullName );
            ListView1->Items->Add( item );
         }
      }
   }
private void PopulateListView()
{
	ListView1.Width = 270;
	ListView1.Location = new System.Drawing.Point(10, 10);

	// Declare and construct the ColumnHeader objects.
	ColumnHeader header1, header2;
	header1 = new ColumnHeader();
	header2 = new ColumnHeader();

	// Set the text, alignment and width for each column header.
	header1.Text = "File name";
	header1.TextAlign = HorizontalAlignment.Left;
	header1.Width = 70;

	header2.TextAlign = HorizontalAlignment.Left;
	header2.Text = "Location";
	header2.Width = 200;

	// Add the headers to the ListView control.
	ListView1.Columns.Add(header1);
	ListView1.Columns.Add(header2);

       // Specify that each item appears on a separate line.
       ListView1.View = View.Details;
       
       // Populate the ListView.Items property.
	// Set the directory to the sample picture directory.
	System.IO.DirectoryInfo dirInfo = 
		new System.IO.DirectoryInfo(
		"C:\\Documents and Settings\\All Users" +
		"\\Documents\\My Pictures\\Sample Pictures");
	

	// Get the .jpg files from the directory
	System.IO.FileInfo[] files = dirInfo.GetFiles("*.jpg");

	// Add each file name and full name including path
	// to the ListView.
	if (files != null)
	{
		foreach ( System.IO.FileInfo file in files )
		{
			ListViewItem item = new ListViewItem(file.Name);
			item.SubItems.Add(file.FullName);
			ListView1.Items.Add(item);
		}
	}
}
Private Sub PopulateListView()
    ListView1.Width = 270
    ListView1.Location = New System.Drawing.Point(10, 10)

    ' Declare and construct the ColumnHeader objects.
    Dim header1, header2 As ColumnHeader
    header1 = New ColumnHeader
    header2 = New ColumnHeader

    ' Set the text, alignment and width for each column header.
    header1.Text = "File name"
    header1.TextAlign = HorizontalAlignment.Left
    header1.Width = 70

    header2.TextAlign = HorizontalAlignment.Left
    header2.Text = "Location"
    header2.Width = 200

    ' Add the headers to the ListView control.
    ListView1.Columns.Add(header1)
    ListView1.Columns.Add(header2)

    ' Specify that each item appears on a separate line.
    ListView1.View = View.Details

    ' Populate the ListView.Items property.
    ' Set the directory to the sample picture directory.
    Dim dirInfo As New System.IO.DirectoryInfo _
        ("C:\Documents and Settings\All Users" _
        & "\Documents\My Pictures\Sample Pictures")
    Dim file As System.IO.FileInfo

    ' Get the .jpg files from the directory
    Dim files() As System.io.FileInfo = dirInfo.GetFiles("*.jpg")

    ' Add each file name and full name including path
    ' to the ListView.
    If (files IsNot Nothing) Then
        For Each file In files
            Dim item As New ListViewItem(file.Name)
            item.SubItems.Add(file.FullName)
            ListView1.Items.Add(item)
        Next
    End If
End Sub

注解

列标题是包含标题文本的ListView控件中的项。A column header is an item in a ListView control that contains heading text. ColumnHeader可以ListView ListView.ColumnHeaderCollection使用类的方法将对象添加到。 AddColumnHeader objects can be added to a ListView using the Add method of the ListView.ColumnHeaderCollection class. 若要向添加一组列ListView, 可以AddRange使用ListView.ColumnHeaderCollection类的方法。To add a group of columns to a ListView, you can use the AddRange method of the ListView.ColumnHeaderCollection class. Index可以使用ColumnHeader类的属性来确定在中ListView.ColumnHeaderCollectionColumnHeader位置。You can use the Index property of the ColumnHeader class to determine where the ColumnHeader is located in the ListView.ColumnHeaderCollection.

ColumnHeaderText提供和TextAlign属性, 以设置在控件中显示的文本以及列标头中文本的对齐方式。ColumnHeader provides the Text and TextAlign properties to set the text displayed in the control and the alignment of the text in the column header. 若要确定ColumnHeader是否ListView与控件关联ListView , 可以引用属性。To determine whether a ColumnHeader is associated with a ListView control, you can reference the ListView property. 如果要复制ColumnHeader以便在其他ListView控件中使用Clone , 可以使用方法。If you want to copy a ColumnHeader for use in another ListView control, you can use the Clone method.

构造函数

ColumnHeader() ColumnHeader() ColumnHeader() ColumnHeader()

初始化 ColumnHeader 类的新实例。Initializes a new instance of the ColumnHeader class.

ColumnHeader(Int32) ColumnHeader(Int32) ColumnHeader(Int32) ColumnHeader(Int32)

用指定的图像初始化 ColumnHeader 类的新实例。Initializes a new instance of the ColumnHeader class with the image specified.

ColumnHeader(String) ColumnHeader(String) ColumnHeader(String) ColumnHeader(String)

用指定的图像初始化 ColumnHeader 类的新实例。Initializes a new instance of the ColumnHeader class with the image specified.

属性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
DisplayIndex DisplayIndex DisplayIndex DisplayIndex

相对于当前所显示各列,获取或设置列的显示顺序。Gets or sets the display order of the column relative to the currently displayed columns.

Events Events Events Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
ImageIndex ImageIndex ImageIndex ImageIndex

获取或设置显示在 ColumnHeader 中的图像的索引。Gets or sets the index of the image displayed in the ColumnHeader.

ImageKey ImageKey ImageKey ImageKey

获取或设置显示在列中的图像的键。Gets or sets the key of the image displayed in the column.

ImageList ImageList ImageList ImageList

获取 ColumnHeader 的关联图像列表。Gets the image list associated with the ColumnHeader.

Index Index Index Index

获取该列在 ListView 控件的 ListView.ColumnHeaderCollection 中的位置。Gets the location with the ListView control's ListView.ColumnHeaderCollection of this column.

ListView ListView ListView ListView

获取 ListView 所位于的 ColumnHeader 控件。Gets the ListView control the ColumnHeader is located in.

Name Name Name Name

获取或设置 ColumnHeader 的名称。Gets or sets the name of the ColumnHeader.

Site Site Site Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
Tag Tag Tag Tag

获取或设置一个对象,该对象包含与 ColumnHeader 关联的数据。Gets or sets an object that contains data to associate with the ColumnHeader.

Text Text Text Text

获取或设置列标题中显示的文本。Gets or sets the text displayed in the column header.

TextAlign TextAlign TextAlign TextAlign

获取或设置 ColumnHeader 中所显示文本的水平对齐方式。Gets or sets the horizontal alignment of the text displayed in the ColumnHeader.

Width Width Width Width

获取或设置列的宽度。Gets or sets the width of the column.

方法

AutoResize(ColumnHeaderAutoResizeStyle) AutoResize(ColumnHeaderAutoResizeStyle) AutoResize(ColumnHeaderAutoResizeStyle) AutoResize(ColumnHeaderAutoResizeStyle)

按照调整大小样式调整列宽。Resizes the width of the column as indicated by the resize style.

Clone() Clone() Clone() Clone()

创建当前 ColumnHeader 的相同副本,它未附加到任何列表视图控件。Creates an identical copy of the current ColumnHeader that is not attached to any list view control.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

处置由 ColumnHeader 占用的资源(内存除外)。Disposes of the resources (other than memory) used by the ColumnHeader.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

事件

Disposed Disposed Disposed Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

适用于

另请参阅