Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações. |
Tradução
Original
|
Classe NodeLabelEditEventArgs
Provides data for the BeforeLabelEdit and AfterLabelEdit events.
Assembly: System.Windows.Forms (em System.Windows.Forms.dll)
The AfterLabelEdit evento ocorre quando o usuário conclui a edição do texto para um nó de árvore. The BeforeLabelEdit evento ocorre quando o usuário começa a edição do texto para um nó de árvore. A NodeLabelEditEventArgs objeto Especifica o novo texto para associar o nó de árvore, o nó de árvore que contém o rótulo para editar, e se a operação de edição foi cancelada.
Para obter mais informações sobre tratamento eventos, consulte Consumindo Eventos.
O exemplo a seguir permite que o usuário edição nós de árvore não-raiz usando um ContextMenu. Quando o usuário botão direito do mouse clicar o mouse, a TreeNode Nesse posição é determinada e armazenada em uma variável chamada mySelectedNode. Se um nó de árvore não-raiz tiver sido selecionado, ela é colocada em um estado editável, permitindo que o usuário edição o rótulo do nó. Depois que o usuário pára de editar o rótulo do nó de árvore, o novo texto de rótulo é avaliado e salvas. Neste exemplo, vários caracteres são considerados inválido válido no texto do rótulo. Se um dos caracteres inválidos é na seqüência de caracteres de rótulo ou a seqüência de caracteres estiver vazia, o usuário é notificado do erro e o rótulo é retornado para o texto anterior.
/* Get the tree node under the mouse pointer and save it in the mySelectedNode variable. */privatevoid treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { mySelectedNode = treeView1.GetNodeAt(e.X, e.Y); } privatevoid menuItem1_Click(object sender, System.EventArgs e) { if (mySelectedNode != null && mySelectedNode.Parent != null) { treeView1.SelectedNode = mySelectedNode; treeView1.LabelEdit = true; if(!mySelectedNode.IsEditing) { mySelectedNode.BeginEdit(); } } else { MessageBox.Show("No tree node selected or selected node is a root node.\n" + "Editing of root nodes is not allowed.", "Invalid selection"); } } privatevoid treeView1_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { if (e.Label != null) { if(e.Label.Length > 0) { if (e.Label.IndexOfAny(newchar[]{'@', '.', ',', '!'}) == -1) { // Stop editing without canceling the label change. e.Node.EndEdit(false); } else { /* Cancel the label edit action, inform the user, and place the node in edit mode again. */ e.CancelEdit = true; MessageBox.Show("Invalid tree node label.\n" + "The invalid characters are: '@','.', ',', '!'", "Node Label Edit"); e.Node.BeginEdit(); } } else { /* Cancel the label edit action, inform the user, and place the node in edit mode again. */ e.CancelEdit = true; MessageBox.Show("Invalid tree node label.\nThe label cannot be blank", "Node Label Edit"); e.Node.BeginEdit(); } this.treeView1.LabelEdit = false; } }
/* Get the tree node under the mouse pointer and
save it in the mySelectedNode variable.
*/
private void treeView1_MouseDown(Object sender,
System.Windows.Forms.MouseEventArgs e)
{
mySelectedNode = treeView1.GetNodeAt(e.get_X(), e.get_Y());
} //treeView1_MouseDown
private void menuItem1_Click(Object sender, System.EventArgs e)
{
if (mySelectedNode != null && mySelectedNode.get_Parent() != null) {
treeView1.set_SelectedNode(mySelectedNode);
treeView1.set_LabelEdit(true);
if (!(mySelectedNode.get_IsEditing())) {
mySelectedNode.BeginEdit();
}
}
else {
MessageBox.Show("No tree node selected or selected node"
+ "is a root node.\n"
+ "Editing of root nodes is not allowed.", "Invalid selection");
}
} //menuItem1_Click
private void treeView1_AfterLabelEdit(Object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
if (e.get_Label()!= null) {
if (e.get_Label().length() > 0) {
if (e.get_Label().IndexOfAny((new char[]{ '@', '.', ',', '!' }))
== -1) {
// Stop editing without canceling the label change.
e.get_Node().EndEdit(false);
}
else {
/* Cancel the label edit action, inform the user, and
place the node in edit mode again.
*/
e.set_CancelEdit(true);
MessageBox.Show("Invalid tree node label.\n"
+ "The invalid characters are: "
+ "'@','.', ',', '!'", "Node Label Edit");
e.get_Node().BeginEdit();
}
}
else {
/* Cancel the label edit action, inform the user, and
place the node in edit mode again.
*/
e.set_CancelEdit(true);
MessageBox.Show("Invalid tree node label.\n"
+ "The label cannot be blank", "Node Label Edit");
e.get_Node().BeginEdit();
}
this.treeView1.set_LabelEdit(false);
}
} //treeView1_AfterLabelEdit
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.