Splitter.SplitterMoved Event


当移动拆分器控件时发生。Occurs when the splitter control is moved. SplitterMoved 已被 SplitterMoved 取代,且仅为与早期版本兼容而提供。SplitterMoved has been replaced by SplitterMoved and is provided only for compatibility with previous versions.

 event System::Windows::Forms::SplitterEventHandler ^ SplitterMoved;
public event System.Windows.Forms.SplitterEventHandler SplitterMoved;
member this.SplitterMoved : System.Windows.Forms.SplitterEventHandler 
Public Custom Event SplitterMoved As SplitterEventHandler 


下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中,事件处理程序报告 SplitterMoved 事件的发生。In the example, an event handler reports on the occurrence of the SplitterMoved event. 此报表可帮助你了解何时发生事件,并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件,请考虑将 MessageBox.Show 替换为 Console.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.

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

private void Splitter1_SplitterMoved(Object sender, SplitterEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "X", e.X );
messageBoxCS.AppendFormat("{0} = {1}", "Y", e.Y );
messageBoxCS.AppendFormat("{0} = {1}", "SplitX", e.SplitX );
messageBoxCS.AppendFormat("{0} = {1}", "SplitY", e.SplitY );
MessageBox.Show(messageBoxCS.ToString(), "SplitterMoved Event" );
Private Sub Splitter1_SplitterMoved(sender as Object, e as SplitterEventArgs) _ 
     Handles Splitter1.SplitterMoved

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "X", e.X)
    messageBoxVB.AppendFormat("{0} = {1}", "Y", e.Y)
    messageBoxVB.AppendFormat("{0} = {1}", "SplitX", e.SplitX)
    messageBoxVB.AppendFormat("{0} = {1}", "SplitY", e.SplitY)
    MessageBox.Show(messageBoxVB.ToString(),"SplitterMoved Event")

End Sub


可以为 SplitterMoved 事件创建事件处理程序,以便在应用程序中执行调整大小验证。You can create an event handler for the SplitterMoved event to perform resize validation in your application. 例如,如果 Splitter 控件停靠到 TreeView 控件的边缘和 ListView 控件上,则可以在 SplitterMoved 事件中编写代码,以确定是否已超出 TreeViewListView 控件的最小值和/或最大大小,并将控件的大小调整为最小值或最大大小。For example, if a Splitter control is docked to the edges of a TreeView control and a ListView control, you can write code in the SplitterMoved event to determine if the minimum and/or maximum size for the TreeView and ListView controls has been exceeded and resize the controls to their minimum or maximum size.

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

Applies to

See also