[Unity] Disable Textbox text Copy / Paste / Cut
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
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
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: [Unity] Disable Textbox text Copy / Paste / Cut
HI,
To disable Copy/Cut/Paste from a TextBox you can detect when their KeyBindings are pressed to avoid executing the corresponding commands:
To disable Copy/Cut/Paste from a TextBox you can detect when their KeyBindings are pressed to avoid executing the corresponding commands:
Code: Select all
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
thank you, i appreciate that i didn't think about using PreviewKeyDownHI,
To disable Copy/Cut/Paste from a TextBox you can detect when their KeyBindings are pressed to avoid executing the corresponding commands:Code: Select allpublic 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; } } }
Regards
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 58 guests