0

我在标点符号后实现了大写。但是如何实现它,用户可以返回并删除第一个单词或字符,因为他想继续小写?

KeyPress(object sender, KeyPressEventArgs e)
{
   if(EndOfSentence())
   {
       e.KeyChar = Char.ToUpper(e.Keychar);
   }
}
//
private bool EndOfSentence()
{
  //return true if end of sentence found
}

例:如果我写这句话。我不能回去把“我”改成“我”!而且我不能将“A”更改为“a”,但我想!如何编码?

此处的示例项目:http ://www.filefactory.com/file/3ecbn51bhbrv/n/Capi.zip

我看到的唯一解决方案是保存当前和上一个键并检查是否按下了退格键或删除键,例如:

if (!EndOfSentence())
{
  previousKeyChar = e.KeyChar;
  return;
}
//
if(previousKeyChar.Equals('\b')) return;
else
e.KeyChar = Char.ToUpper(e.KeyChar);
//
//
// And in the EndOfSentence I Check
// if the cursor is at the end of the text
if(textbox1.Text.Length != textbox1.SelectionStart)
  return false; //allow editing in the middle of the text
4

2 回答 2

0

There may be better ways, but one is to store the entire sentence in a collection and check against the collection before modifying it again.

于 2012-04-17T08:56:25.117 回答
0

或者,您可以尝试将EndOfSentence函数更改为仅在输入结束时才返回 true。这样,它应该只大写在输入末尾键入的字符,如果您在文本中间编辑某些内容,它应该保持不变

于 2012-04-17T09:05:05.933 回答