1

Currently in my WPF app I have a multiple textbox readonly. So the user can select text and then Ctrl+C Ctrl+V. But I want to make this task more simple :

  • If the user just left click on the textbox (or another control that display my text), all the text is copy to clipboard

But the user still has the possibility to select the text as before

Any idea to do that in a XAML style ?


It is solve, I will automatically copy to clipboard any text selected. Knowing that if you doubleclick on a textbox it select all text, the user will just have to doubleclick to copy all the text in his clipboard.

Community
  • 1
  • 1
Pak
  • 2,639
  • 2
  • 21
  • 27

2 Answers2

2

As for the mouse over animation. Take the mouseover animation and change the pointer while the mouse is inside the bounds of the button. Here is a link about mouseover events:

http://dotnetdud.blogspot.com/2009/01/how-to-use-c-mouseover-events-in.html

Here is how you can set your clipboard data on the textbox mouseclick event:

private void textbox_mouseClick(object sender, EventArgs e)
    {
    if (((TextBox)sender).Text == string.Empty)
        return;
    else
       {
        try
         {
        Clipboard.SetText(((TextBox)sender).Text);
         }
        catch (Exception ex)
         {
           // Do something w/ exception 
         }
       }
    }
Botonomous
  • 1,746
  • 1
  • 16
  • 39
1

For your clipboard problem, you can create an onclick handler and use the built-in clipboard functionality in C# (How to copy data to clipboard in C#).

For the tooltip, you'll need to use an onload handler and the built-in tooltip functionality in C#:

System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.textBox1, "Hello");

Haven't done much with animations, but if I'm not mistaken, you can set an onhover handler as well. (Edit: The MouseHover event handler is probably what you're looking for.)

Edit: Basically, event handlers are your friends.

Community
  • 1
  • 1
sichinumi
  • 1,835
  • 3
  • 21
  • 40
  • I would like to do that in a style in xaml not in code behind :/ – Pak Jun 01 '12 at 21:06
  • Ah, I see. I'm not sure if you can achieve the clipboard functionality you're looking for, but for your mouse hover functionality, take a look at this: http://stackoverflow.com/questions/2388429/how-to-set-mouseover-event-trigger-for-border-in-xaml - For your tool tip, take a look at this: http://blogs.msdn.com/b/tom_mathews/archive/2006/11/06/binding-a-tooltip-in-xaml.aspx – sichinumi Jun 01 '12 at 21:10