Question : RichTextbox 256 characters

I have a RichTextBox going to a sql2005 express database which only has 256 characters.  Instead of validating the data and doing a popup box, is there a way that I can set the richtext box to only allow 256 characters.  I tried to set that in properties>maxlength to 256, but it would not allow me to type anything.  Also can I make it to where the cursor starts at the very left of the box.  I tried to set the indention to 0 but that does not appear to work.

Answer : RichTextbox 256 characters

i think the best way to limit the user input to 256 characters is to handle the KeyPress event as in the code below. this will simply ignore any key presses after the text length reaches 256
1:
2:
3:
4:
5:
6:
7:
8:
9:
richTextBox1.KeyPress += new KeyPressEventHandler(richTextBox1_KeyPress);

...

        void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (richTextBox1.Text.Length > 256)
                e.Handled = true;
        }
Random Solutions  
 
programming4us programming4us