DataGridView.ColumnDividerDoubleClick DataGridView.ColumnDividerDoubleClick DataGridView.ColumnDividerDoubleClick DataGridView.ColumnDividerDoubleClick Event

定义

用户双击两列之间的分隔符时发生。Occurs when the user double-clicks a divider between two columns.

public:
 event System::Windows::Forms::DataGridViewColumnDividerDoubleClickEventHandler ^ ColumnDividerDoubleClick;
public event System.Windows.Forms.DataGridViewColumnDividerDoubleClickEventHandler ColumnDividerDoubleClick;
member this.ColumnDividerDoubleClick : System.Windows.Forms.DataGridViewColumnDividerDoubleClickEventHandler 
Public Custom Event ColumnDividerDoubleClick As DataGridViewColumnDividerDoubleClickEventHandler 

示例

下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中, 事件处理程序报告ColumnDividerDoubleClick事件的发生。In the example, an event handler reports on the occurrence of the ColumnDividerDoubleClick event. 此报表可帮助你了解何时发生事件, 并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件, 请考虑MessageBox.ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要运行示例代码, 请将其粘贴到包含名为DataGridView DataGridView1的类型的实例的项目中。To run the example code, paste it into a project that contains an instance of type DataGridView named DataGridView1. 然后, 确保事件处理程序与ColumnDividerDoubleClick事件相关联。Then ensure that the event handler is associated with the ColumnDividerDoubleClick event.

private void DataGridView1_ColumnDividerDoubleClick(Object sender, DataGridViewColumnDividerDoubleClickEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Handled", e.Handled );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Button", e.Button );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Clicks", e.Clicks );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "X", e.X );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Y", e.Y );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Delta", e.Delta );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Location", e.Location );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "ColumnDividerDoubleClick Event" );
}
Private Sub DataGridView1_ColumnDividerDoubleClick(sender as Object, e as DataGridViewColumnDividerDoubleClickEventArgs) _ 
     Handles DataGridView1.ColumnDividerDoubleClick

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Handled", e.Handled)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Button", e.Button)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Clicks", e.Clicks)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "X", e.X)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Y", e.Y)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Delta", e.Delta)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Location", e.Location)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"ColumnDividerDoubleClick Event")

End Sub

注解

可以使用此事件自定义用户双击列分隔符时发生的自动调整大小行为。You can use this event to customize the automatic sizing behavior that occurs when a user double-clicks a column divider. 例如,你可以处理此事件以编程方式仅基于当前可见行中的内容来调整列的大小,以避免在处理大量行时对默认行为产生的性能影响。For example, you can handle this event to programmatically resize columns based only on the content in the rows that are currently visible, avoiding a performance impact with the default behavior when working with a large number of rows.

"列DividerWidth " 属性不会扩展用户可以双击的区域。The column DividerWidth property does not extend the area in which a user can double-click. 如果通过使用此属性增加了分隔线的宽度,则当用户双击分隔符与相邻列之间的边界时发生此事件。If the width of a divider has been increased through the use of this property, this event occurs when the user double-clicks the boundary between the divider and the adjacent column.

有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.

适用于

另请参阅