111,092
社区成员




private int h;
private int w;
private int lineH;//行高
private int line = 11;// 标准行数量
private int midLine = 11;//中间变量line
private int currentLine = 1;
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
RichTextBox r = (RichTextBox)sender;
currentLine = r.GetLineFromCharIndex(r.SelectionStart) + 1;
this.Text = "line:"+line+",LinesLength:"+this.richTextBox1.Lines.Length.ToString()+",currentLine:"+currentLine;
if (e.KeyData == Keys.Enter)
{
//如果是最后一行的话,那么将他的高度自动增长一行
if (richTextBox1.Lines.Length > = line)
{
r.SetBounds(r.Location.X, r.Location.Y, r.Width, r.Height + lineH);
}
}
else if (e.KeyData == Keys.Delete)
{
if (richTextBox1.Lines.Length > line && currentLine != r.Lines.Length)//如果richtextbox总行数大于标准行数,且不是最后一行
{
r.SetBounds(r.Location.X, r.Location.Y, r.Width, r.Height - lineH);
//e.Handled = true;
}
}
else if (e.KeyData == Keys.Back)
{
if (richTextBox1.Lines.Length > line)//如果richtextbox总行数大于标准行数,
{
r.SetBounds(r.Location.X, r.Location.Y, r.Width, r.Height - lineH);
//e.Handled = true;
}
}
}
this.richTextBox1.ScrollBars = RichTextBoxScrollBars.None;