[Unity] Disable Textbox text Copy / Paste / Cut
Posted: 17 Dec 2015, 02:44
by b1qb0ss
Hello,
First I'm new to Noesis
since Unity isn't using .Net 4 i can't use the disable the text selection from textboxes
i tried detecting the Control Key and set the selection length to 0 but that doesn't work i still can select text
Thanks in Advance
Re: [Unity] Disable Textbox text Copy / Paste / Cut
Posted: 19 Dec 2015, 12:37
by sfernandez
HI,
To disable Copy/Cut/Paste from a TextBox you can detect when their KeyBindings are pressed to avoid executing the corresponding commands:
public class DisableCopyCutPaste: MonoBehaviour
{
void Start()
{
var gui = GetComponent<NoesisGUIPanel>();
var content = gui.GetContent();
var txt = (TextBox)content.FindName("myTextBox");
txt.PreviewKeyDown += txt_PreviewKeyDown;
}
void txt_PreviewKeyDown(object sender, KeyEventArgs e)
{
Keyboard kb = ((UIElement)sender).GetKeyboard();
bool ctrl = kb.IsKeyDown(Key.Control);
bool shift = kb.IsKeyDown(Key.Shift);
if ((ctrl && e.Key == Key.C) || (ctrl && e.Key == Key.Insert) ||
(ctrl && e.Key == Key.X) || (shift && e.Key == Key.Delete) ||
(ctrl && e.Key == Key.V) || (shift && e.Key == Key.Insert))
{
e.Handled = true;
}
}
}
Re: [Unity] Disable Textbox text Copy / Paste / Cut
Posted: 19 Dec 2015, 20:52
by b1qb0ss
HI,
To disable Copy/Cut/Paste from a TextBox you can detect when their KeyBindings are pressed to avoid executing the corresponding commands:
public class DisableCopyCutPaste: MonoBehaviour
{
void Start()
{
var gui = GetComponent<NoesisGUIPanel>();
var content = gui.GetContent();
var txt = (TextBox)content.FindName("myTextBox");
txt.PreviewKeyDown += txt_PreviewKeyDown;
}
void txt_PreviewKeyDown(object sender, KeyEventArgs e)
{
Keyboard kb = ((UIElement)sender).GetKeyboard();
bool ctrl = kb.IsKeyDown(Key.Control);
bool shift = kb.IsKeyDown(Key.Shift);
if ((ctrl && e.Key == Key.C) || (ctrl && e.Key == Key.Insert) ||
(ctrl && e.Key == Key.X) || (shift && e.Key == Key.Delete) ||
(ctrl && e.Key == Key.V) || (shift && e.Key == Key.Insert))
{
e.Handled = true;
}
}
}
thank you, i appreciate that i didn't think about using PreviewKeyDown
Regards