Answer the question
In order to leave comments, you need to log in
How to block new line transition on pressing Enter in RichTextBox(multiline)?
Hello! Such a problem: there is a RichTextBox element on the form, which serves as a message entry field. By pressing Enter, it sends the text in the sting line to the right place. But in addition to the action I programmed, another default one is performed - a transition to a new line. I need only 1 action to be performed (sending a message) and not a line break.
Thus if the user presses shift+enter - transition to a new line occurs.
So how do I block the default function Enter'a? I've been looking for an answer for a long time and I can't find it, it seems to be such a simple action.
Answer the question
In order to leave comments, you need to log in
What am I doing wrong?
class Categories
{
public function __construct($db){
$this->db = $db;
}
public function getCategories()
{
$query="SELECT * FROM categories";
return $this->db->query($query)->fetchAll();
}
}
include 'pdo.php';
$category = new Categories($pdo);
$list = $category->getCategories();
Return in the constructor does not work. Object instance always rises
The only way that comes to my mind is not very simple.
Determine which of the events (KeyPress, KeyDown, KeyUp, PreviewKeyDown) this action falls on, after which
1) remove all default handlers with reflection,
2) process them manually.
You can remove the handler, for example, with the following code (example for the Click event, respectively, for your EventClick string content will change, you need a field responsible for your events)
instead of panel1 - respectively, your richTextBox:
FieldInfo f1 = typeof(Control).GetField("EventClick", BindingFlags.Static| BindingFlags.NonPublic);
object obj = f1.GetValue(panel1);
PropertyInfo pi = panel1.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
EventHandlerList list = (EventHandlerList)pi.GetValue(panel1, null);
list.RemoveHandler(obj, list[obj]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question