توی یه کد فایل:
namespace Win32API
{
public class Windows
{
const int WM_SETTEXT = 12;
const int WM_KEYDOWN = 256;
const int WM_KEYUP = 257;
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern bool SetControlTextSendMessage(Int32 hWnd, Int32 wMsg, Int32 wParam, string lParam);
public static void SetControlText(System.Windows.Forms.IWin32Window Control, string Text)
{
SetControlTextSendMessage(Control.Handle.ToInt32() , WM_SETTEXT, 0, Text);
}
public static void SetControlText(System.Windows.Forms.TextBoxBase Control, string Text)
{
SetControlTextSendMessage(Control.Handle.ToInt32() , WM_SETTEXT, 0, Control.Text.Substring(0, Control.SelectionStart) + Text + Control.Text.Substring(Control.SelectionStart + Control.SelectionLength));
}
}
}
توی فرم Load :
txtbox1.Text="AB";
Win32API.Windows.SetControlText(this, "Hello");
txtbox1.SelectionStart = 0; Win32API.Windows.SetControlText(this.txtbox1, "1");
txtbox1.SelectionStart = 2; Win32API.Windows.SetControlText(this.txtbox1, "2");
txtbox1.SelectionStart = 4; Win32API.Windows.SetControlText(this.txtbox1, "3");