如果我预插入了几个textfield,并且将其 Deleteable 、Editable 属性值都设为 false;当光标从别的地方再点回最后一个textfield的后面,此时希望通过textcontrol.changed事件,获取输入的字符,并将该字符存进一个新的textfield内。
贴上代码:
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
TextField tf = new TextField();
tf.Name = i.ToString();
tf.Text = i.ToString();
tf.Deleteable = false;
tf.Editable = false;
this.textControl1.TextFields.Add(tf);
}
}
private void textControl1_Changed(object sender, EventArgs e)
{
string currentName = "删除人"; //当前删除人
TextControl tce = (TextControl)sender;
int delID = 0;
int currentLine = tce.InputPosition.Line;
int currentColumn = tce.InputPosition.Column;
int currentPage = tce.InputPosition.Page;
int start = tce.InputPosition.TextPosition;
int length = 1;
tce.Selection.Start = start - 1;
tce.Selection.Length = length;
tce.Selection.ForeColor = Color.LightSkyBlue;
tce.Selection.Underline = FontUnderlineStyle.SingleWordsOnly;
TextField delTextField = new TextField();
delTextField.ID = delID;
delID++;
delTextField.Name += "由 " + currentName + " 在 " + DateTime.Now.ToString() + " 插入.#";
delTextField.Text = tce.Selection.Text;
tce.Selection.Text = "";
tce.TextFields.Add(delTextField);
tce.InputFormat.TextColor = Color.Black;
tce.InputFormat.Strikeout = false;
}
private void textControl1_TextFieldClicked(object sender, TextFieldEventArgs e)
{
this.textControl1.Select(e.TextField.Start, 1);
string selectText = this.textControl1.Selection.Text;
this.textControl1.Selection.Text = " " + selectText;
this.textControl1.Select(e.TextField.Start, 1);
this.textControl1.Selection.Text = "";
}
private void changed事件ToolStripMenuItem_Click(object sender, EventArgs e)
{
textControl1.Changed+=new EventHandler(textControl1_Changed);
}
这个是否可以认为是插入点停留在了最后一个textfield内?用了4#的代码,也还是一样的效果 |