ListControl.Format 事件

定義

發生於控制項繫結至資料值時。Occurs when the control is bound to a data value.

public:
 event System::Windows::Forms::ListControlConvertEventHandler ^ Format;
public event System.Windows.Forms.ListControlConvertEventHandler Format;
member this.Format : System.Windows.Forms.ListControlConvertEventHandler 
Public Custom Event Format As ListControlConvertEventHandler 

範例

下列程式碼範例示範如何使用這個成員。The following code example demonstrates the use of this member. 在此範例中,事件處理常式會報告 Format 事件的發生。In the example, an event handler reports on the occurrence of the Format event. 此報表可協助您瞭解事件發生的時間,並可協助您進行調試。This report helps you to learn when the event occurs and can assist you in debugging. 若要報告多個事件或經常發生的事件,請考慮使用 Console.WriteLine 取代 MessageBox.Show,或將訊息附加到多行 TextBoxTo 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.

若要執行範例程式碼,請將它貼入包含繼承自 ListControl之類型實例的專案,例如 ComboBoxListBoxTo run the example code, paste it into a project that contains an instance of a type that inherits from ListControl, such as a ComboBox or ListBox. 然後將實例命名為 ListControl1,並確定事件處理常式與 Format 事件相關聯。Then name the instance ListControl1 and ensure that the event handler is associated with the Format event.

private void ListControl1_Format(Object sender, ListControlConvertEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ListItem", e.ListItem );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Value", e.Value );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "DesiredType", e.DesiredType );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "Format Event" );
}
Private Sub ListControl1_Format(sender as Object, e as ListControlConvertEventArgs) _ 
     Handles ListControl1.Format

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ListItem", e.ListItem)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Value", e.Value)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "DesiredType", e.DesiredType)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"Format Event")

End Sub

備註

Format 事件會在 ListControl 中的每個可見專案格式化之前引發。The Format event is raised before each visible item in the ListControl is formatted. 處理這個事件可讓您透過 ListControlConvertEventArgsValue 屬性,存取要針對此清單專案顯示的字串。Handling this event gives you access to the string to be displayed for this list item, through the Value property of the ListControlConvertEventArgs.

如需處理事件的詳細資訊,請參閱處理和引發事件For more information about handling events, see Handling and Raising Events.

適用於