locked
How do I make a textbox resize with my form? RRS feed

  • Question

  • I want to create my own version of notepad but before I actually do anything, I want to get it looking right. 
    So, just like the default notepad, I want my text box to constantly fit the form as I re-size it. Currently, if I maximize the program the box stays the same size and I get a large gray area. I also have a menu and status strip so it needs to fit between them and not go behind them. How would I go about doing this?
    Sunday, December 23, 2012 3:46 AM

Answers

  • Hi,

    I understood that you are using Windows Forms. You created a form with a control and you want that the control is resized together with the form.

    You should check out the anchor property of the control. With that property, you can make sure, that the distance between the border of the control and the border of the control it is in (in your case the form) is always the same. (Please see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor for details about the Anchor property!)

    If this does not fit your requirements because you need a more complex sizing / positioning, then you can resize / move the control on your own. The Resize event of the parent control is the event that you should subscribe to.

    I hope this helped a little bit.

    With kind regards,

    Konrad

    Sunday, December 23, 2012 11:45 AM