How to select all and copy text from all controls?

In a WPF window I have 6 DataGrid and 6 Label. Is it possible to add a right-click menu to the window and select the text from all controls and then copy this text?

 3
Author: Chofoteddy, 2016-09-26

1 answers

If I'm not mistaken here's a precise tutorial on how to do that: https://freelanceprogramer.wordpress.com/2013/11/10/seleccionar-automaticamente-todo-el-texto-en-foco-en-el-control-textbox-de-wpf/. explain what you want to do, it gives you the scripts that you should use.

As the tutorial explains, We must create a static variable:

static bool conFoco_txtBuscar; (esta variable establece si el texto se encuentra “con foco” = “true” ó “false”)

EVENTO GodFocus:

gotfocus  

EVENTO GotMouseFocus:

gotmousefocus

EVENTO LostFocus

lostfocus

Here I leave the same code in text format since the code above are images and you can not copy the clipboard text:

/*variable estatica*/

static bool conFoco_txtBuscar;

/*eventos*/

private void txtBuscarCliente_GotFocus(object sender, RoutedEventArgs e)
{
          if (Mouse.LeftButton == MouseButtonState.Released)
          {
                    txtBuscarCliente.SelectAll();
                    conFoco_txtBuscar = true;
          }
}

private void txtBuscarCliente_GotMouseCapture(object sender, MouseEventArgs e)
{
          if (!conFoco_txtBuscar && txtBuscarCliente.SelectionLength == 0)
          {
                    conFoco_txtBuscar = true;
                    txtBuscarCliente.SelectAll();
          }
}

private void txtBuscarCliente_LostFocus(object sender, RoutedEventArgs e)
{
          conFoco_txtBuscar = false;
          txtBuscarCliente.SelectionLength = 0;
}
 2
Author: Lucas D.A.W., 2017-08-27 14:45:42