Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a textbox stretch to its parent window's width in C#?

I have a TextBox which I would like to have stretch to its parent's Width.

I tried anchoring Top, Left, Right but that only goes just over about 60%, any ideas?

like image 570
futureslay Avatar asked Oct 22 '25 05:10

futureslay


1 Answers

As Hans Passant said in a comment, but anchor to the left as well.

Or, if you want to do it programmatically:

textBox1.Width = textBox1.Parent.Width;
textBox1.Location = new Point(0,textBox1.Location.Y);
textBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
like image 107
ispiro Avatar answered Oct 25 '25 11:10

ispiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!