Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Löst das AfterLabelEdit-Ereignis aus.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Protected Overridable Sub OnAfterLabelEdit ( _
e As LabelEditEventArgs _
)
'Usage
Dim e As LabelEditEventArgs
Me.OnAfterLabelEdit(e)
protected virtual void OnAfterLabelEdit (
LabelEditEventArgs e
)
protected:
virtual void OnAfterLabelEdit (
LabelEditEventArgs^ e
)
protected void OnAfterLabelEdit (
LabelEditEventArgs e
)
protected function OnAfterLabelEdit (
e : LabelEditEventArgs
)
Parameter
- e
Eine Instanz von LabelEditEventArgs, die die Ereignisdaten enthält.
Hinweise
Durch das Auslösen eines Ereignisses wird der Ereignishandler über einen Delegaten aufgerufen. Weitere Informationen finden Sie unter Auslösen eines Ereignisses.
Mit der OnAfterLabelEdit-Methode können auch abgeleitete Klassen das Ereignis ohne Anfügen eines Delegaten behandeln. Dies ist das bevorzugte Verfahren für die Behandlung des Ereignisses in einer abgeleiteten Klasse.
Hinweise für Erben Wenn Sie OnAfterLabelEdit in einer abgeleiteten Klasse überschreiben, müssen Sie die OnAfterLabelEdit-Methode der Basisklasse aufrufen, sodass registrierte Delegaten das Ereignis empfangen.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie Sie mithilfe des AfterLabelEdit-Ereignisses eine neu bearbeitete Beschriftung auf alphabetische Zeichen beschränken. Im Beispiel wird der entsprechende ASCII-Zeichencode für alle Zeichen der neuen Beschriftung mit der ASCIIEncoding-Klasse abgerufen. Wenn der ASCII-Code eines Zeichens eine Ziffer darstellt, kann die neue Beschriftung nicht auf das Element angewendet werden. Für dieses Beispiel müssen Sie ein ListView-Steuerelement in einem Formular erstellt und diesem Elemente hinzugefügt haben. Zudem müssen Sie für dieses Beispiel das AfterLabelEdit-Ereignis dem im Beispielcode definierten Ereignishandler zugeordnet haben. Um die ASCIIEncoding-Klasse verwenden zu können, muss die Datei den System.Text-Namespace enthalten.
Private Sub MyListView_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.LabelEditEventArgs) Handles listView1.AfterLabelEdit
' Determine if label is changed by checking to see if it is equal to Nothing.
If e.Label = Nothing Then
Return
End If
' ASCIIEncoding is used to determine if a number character has been entered.
Dim AE As New ASCIIEncoding()
' Convert the new label to a character array.
Dim temp As Char() = e.Label.ToCharArray()
' Check each character in the new label to determine if it is a number.
Dim x As Integer
For x = 0 To temp.Length - 1
' Encode the character from the character array to its ASCII code.
Dim bc As Byte() = AE.GetBytes(temp(x).ToString())
' Determine if the ASCII code is within the valid range of numerical values.
If bc(0) > 47 And bc(0) < 58 Then
' Cancel the event and return the lable to its original state.
e.CancelEdit = True
' Display a MessageBox alerting the user that numbers are not allowed.
MessageBox.Show("The text for the item cannot contain numerical values.")
' Break out of the loop and exit.
Return
End If
Next x
End Sub
private void MyListView_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e)
{
// Determine if label is changed by checking for null.
if (e.Label == null)
return;
// ASCIIEncoding is used to determine if a number character has been entered.
ASCIIEncoding AE = new ASCIIEncoding();
// Convert the new label to a character array.
char[] temp = e.Label.ToCharArray();
// Check each character in the new label to determine if it is a number.
for(int x=0; x < temp.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(temp[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if(bc[0] > 47 && bc[0] < 58)
{
// Cancel the event and return the lable to its original state.
e.CancelEdit = true;
// Display a MessageBox alerting the user that numbers are not allowed.
MessageBox.Show ("The text for the item cannot contain numerical values.");
// Break out of the loop and exit.
return;
}
}
}
private:
void MyListView_AfterLabelEdit( Object^ /*sender*/, System::Windows::Forms::LabelEditEventArgs^ e )
{
// Determine if label is changed by checking for 0.
if ( e->Label == nullptr )
return;
// ASCIIEncoding is used to determine if a number character has been entered.
ASCIIEncoding^ AE = gcnew ASCIIEncoding;
// Convert the new label to a character array.
array<Char>^temp = e->Label->ToCharArray();
// Check each character in the new label to determine if it is a number.
for ( int x = 0; x < temp->Length; x++ )
{
// Encode the character from the character array to its ASCII code.
array<Byte>^bc = AE->GetBytes( temp[ x ].ToString() );
// Determine if the ASCII code is within the valid range of numerical values.
if ( bc[ 0 ] > 47 && bc[ 0 ] < 58 )
{
// Cancel the event and return the lable to its original state.
e->CancelEdit = true;
// Display a MessageBox alerting the user that numbers are not allowed.
MessageBox::Show( "The text for the item cannot contain numerical values." );
// Break out of the loop and exit.
return;
}
}
}
private void MyListView_AfterLabelEdit(Object sender,
System.Windows.Forms.LabelEditEventArgs e)
{
// Determine if label is changed by checking for null.
if (e.get_Label() == null) {
return;
}
// ASCIIEncoding is used to determine
// if a number character has been entered.
ASCIIEncoding ae = new ASCIIEncoding();
// Convert the new label to a character array.
char temp[] = e.get_Label().ToCharArray();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < temp.get_Length(); x++) {
// Encode the character from the character array to its ASCII code.
ubyte bc[] = ae.GetBytes(temp.get_Item(x).ToString());
// Determine if the ASCII code is within the valid range
// of numerical values.
if (Convert.ToInt32(bc.get_Item(0)) > 47
&& Convert.ToInt32(bc.get_Item(0)) < 58) {
// Cancel the event and return the lable to its original state.
e.set_CancelEdit(true);
// Display a MessageBox alerting the user that
// numbers are not allowed.
MessageBox.Show("The text for the item cannot contain "
+ "numerical values.");
// Break out of the loop and exit.
return;
}
}
} //MyListView_AfterLabelEdit
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ListView-Klasse
ListView-Member
System.Windows.Forms-Namespace
AfterLabelEdit
LabelEditEventArgs-Klasse