[Solved] Limiting size of input to the size of a TextBox in C#


The properties of the textbox give you a max length, you can also do it in code like so

var tb = new TextBox();
tb.MaxLength = 10

if you don’t want to use that then you should use

var str = tb.Text.Remove(0, 10) 

this will only give the str variable the first 10 characters no matter the length of whats actually in the textbox.

For what you want on form two, you need to give me more information about what you want.


edit after OP’s edit

if you want the text in the textbox to be matched at the label level you want add a TextChanged Event to the property of the textbox and then have something like this

private void TextChanged(object sender, EventArgs e)
{
    label1.Text = textBox1.Text;
}

having the label to a fixed size no matter what is isn’t going to be good, ive done it, but this also begs the question, why are you duplicating your textbox information into a label. Why not just have it in a textbox

3

solved Limiting size of input to the size of a TextBox in C#