, - event, .
"", : , , , . , , , , , , . TextBox .
, :
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static IntPtr SendMessage(IntPtr hwnd, uint message, IntPtr wParam, IntPtr lParam);
private const uint EM_SETWORDBREAKPROC = 0x00D0;
private delegate int SetWordBreakProc(IntPtr text, int pos_in_text, int bCharSet, int action);
private readonly SetWordBreakProc _wordBreakCallback = (text, pos_in_text, bCharSet, action) => 0;
public Form1()
{
InitializeComponent();
textBox1.HandleCreated += TextBox1_HandleCreated;
}
private void TextBox1_HandleCreated(object sender, EventArgs e)
{
IntPtr callback = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_wordBreakCallback);
SendMessage(((Control)sender).Handle, EM_SETWORDBREAKPROC, IntPtr.Zero, callback);
}
}
, TextBox.HandleCreated TextBox.HandleCreated. : -, , , TextBox.Text , , -, , TextBox.Text , , Designer. , .
, , , , , , . , , .
Also note that the above requires explicit initialization of each TextBoxyou added to the form. Obviously, if you want to apply this technique to more than one TextBox, it makes sense to create a new subclass TextBoxthat performs this initialization in its own OnHandleCreated()override OnHandleCreated().